What I am specifically trying to do
symbol_list = ["....firstline.\\.||hi",
"pythonisasnake..\....",
"||||last.\\|line\\..."]
normal_list = ["ABCDfirstlineEFGHIJhi",
"pythonisasnakeKLMNOPQ",
"RSTUlastVWXYlineZABCD"]
In the symbol_list, I want to replace symbols with the letter in the corresponding position in normal_list and I want to replace the non-symbols in the list with a *
- The symbols will always be
.\|
The expected output:
new_list = ["ABCD*********EFGHIJ**",
"**************KLMNOPQ",
"RSTU****VWXY****ZABCD"]
What is the solution to doing this?
What I tried to do
For both lists, I somehow needed to access every item in each row which seemed really complicated to do. I tried to start this with for loops:
for symbol_row in symbol_list:
for symbol_item in symbol_row:
for normal_row in normal_list:
for normal_item in normal_row:
This was confusing and it seems as if it is recommended to do at most two
I then tried to check one of the conditions:
if symbol_item in (".","\\","|"): # because \ is an escape character
symbol_row = symbol_row.replace(symbol_item, normal_item)
Then I appended this new row to new_list but my list ended up 10 times longer than it was before after I printed it out
new_list.append(symbol_row)