I have modified a simple search list in list (codes borrowed from another site) but unable to capture all the relevant information.
INPUT FILE :
data = [['a','b'], ['a','c'], ['b','d'],['a','b']]
I am searching the whole list with a 'b' in it but my algorithm only captures anything ending with a 'b'. I could not capture all 'b' whether it starts in Index(0) or Index(1).
data = [['a','b'], ['a','c'], ['b','d'],['a','b']]
search = 'b'
for sublist in data:
if sublist[1] == search:
print("Found it!" + str(sublist))
Below is the OUTPUT but it is missing ['b','d']. Could someone help please?
Found it!['a', 'b']
Found it!['a', 'b']
sublist[1] == search, i.e. if and only if second element of sublist is equal tosearch. Change it tosearch in sublistand it should be fine.