I have two lists and want to check if elements from first list are in the second list. If true, I want to remove the matched element from a copy of my first list.
my_list = [
'100a',
'100b',
'100c'
]
your_list = [
'100a_nnb',
'100b_ub',
'100c_AGGtb'
]
my_list_2 = my_list
for i in my_list:
for j in your_list:
if i in j:
print(f'Yes, {i} is in {j}!')
#my_list_2.remove(i)
break
else:
print(f'No, {i} is not in {j}!')
When I leave my_list_2.remove(i)
comment out, I got as expected:
Yes, 100a is in 100a_nnb!
No, 100b is not in 100a_nnb!
Yes, 100b is in 100b_ub!
No, 100c is not in 100a_nnb!
No, 100c is not in 100b_ub!
Yes, 100c is in 100c_AGGtb!
When I remove # it gives me:
Yes, 100a is in 100a_nnb!
No, 100c is not in 100a_nnb!
No, 100c is not in 100b_ub!
Yes, 100c is in 100c_AGGtb!
Why is that? It seems that it skips every second list item.