I would do something like this:
[(i, colour.index(c)) for i, colour in enumerate(colours) if c in colour]
This will return a list of tuples where the first index is the position in the first list and the second is the position in the second list (note: c is the color you are looking for, ie "#660000" ).
For example, in the question, the return value is:
[(0, 0)]
If you just need to find the first position in which the color is found in a lazy way, you can use this:
next(((i, colour.index(c)) for i, colour in enumerate(colours) if c in colour), None)
This will return a tuple for the first element found, or None if no element is found (you can also remove the None argument above, it will raise a StopIteration exception if the element is not found).
Edit: as @RikPoggi correctly points out, if the number of matches is large, this will lead to some overhead because the colour repeated twice to find c . I suggested that this is reasonable for a small number of matches and for an answer in a single expression. However, to avoid this, you can also define a method using the same idea as the following:
def find(c): for i, colour in enumerate(colours): try: j = colour.index(c) except ValueError: continue yield i, j matches = [match for match in find('#660000')]
Note that since find is a generator, you can actually use it, as in the above example, with next to stop at the first match and skip further.
jcollado
source share