I'm currently stuck looking for a good solution for the following list comprehension question:
It is easy to find equal values ββwith the same index in two lists, for example
>>> vec1 = [3,2,1,4,5,6,7] >>> vec2 = [1,2,3,3,5,6,9] >>> [a for a, b in zip(vec1, vec2) if a == b] [2,5,6]
However, I need indexes on the lists where these matches occur, and not the values ββthemselves. Using the above example, I want: [1,4,5]
I was busy, but I could only think of a "multi-line" solution. Does anyone know how I can find indexes in a more pythonic way?
source share