I have two lists:
l1 = ['#', '1', '#', '!']
l2 = ['S', 'T', 'K', 'M']
If there is a ‘#’ in l1 I want to remove it, and remove whatever is at the same position in l2.
This is what I have tried (among several other things):
for i in range(len(li[j])):
for k in range(len(l2[n])):
if j == "#":
li.remove([j][i])
l2.remove([n][k])
But it complains that j is not defined.
I want the outcome to look like this:
l1 = ['1', '!']
l2 = ['T', 'M']
I would be grateful for suggestions!
Here is a simple and easy to understand method:
Personally I find it much simplier to understand and more effective (read: “faster”) than the method @jamylak proposed.
Output: