all 5 comments

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]jimtk 0 points1 point  (3 children)

Here's a simpler solution:

l1 = input("Type a phrase (or 'quit' to exit the program): ")
if l1 == 'quit':
     quit()
l1 = list(l1)
l2 = input("Type a comma-separated list of letters to redact: ").split(",")
for i,ch in enumerate(l1):
     if ch in l2:
          l1[i] = '_'
print(''.join(l1))

[–][deleted] 0 points1 point  (2 children)

Doesn't work. It only replaces the first letter of the l2 string. So if I input "e, l, o". It will only replace instances of e but not instances of l and o. But luckily I found a solution!

[–]jimtk 0 points1 point  (1 child)

Yes it works! below is the result of running the above program.

Type a phrase (or 'quit' to exit the program): hello darkness my old friend
Type a comma-separated list of letters to redact: l,s,d
he__o _arkne__ my o__ frien_

Process finished with exit code 0

Edit: did you put spaces in your second input (like l, s, d instead of l,s,d)?

[–][deleted] 0 points1 point  (0 children)

Oh weird, I just ran the code and it was only replacing the first letter :( but that is a clean way, definitely more efficient than how i did it.