If I have a grid of strings such as:
grid = ['ABC','DEF','GHI']
myletter = 'D' grid = ['ABC','DEF','GHI'] for index, value in enumerate(grid): if myletter in value: subindex = value.index(myletter) break print [index, subindex]
So what's going on... If you want to loop through a list and access the index while you're at it, the best way to do this is enumerate.
The easiest way to test if something is in a string or a list is just to test if it is in it. That is
value in L returns true if the value is in the list L. Finally for lists and strings,
L.index(thing) gives you the index of that thing.