Python: Trying to get index of an intersection

Posted by user1620716 on Stack Overflow See other posts from Stack Overflow or by user1620716
Published on 2012-09-25T15:30:12Z Indexed on 2012/09/25 15:37 UTC
Read the original article Hit count: 290

Filed under:
|
|

I have the following line of code:

for i in [i for i,x in enumerate(catdate) if x == set(NNSRCfile['datetimenew']).intersection(catdate)]:
    print i

I am trying to find the index of the intersection for the two components above. Both are lengthy lists that have several commonalities. The intersection part works perfectly; however, the for loop seems to output nothing. (ie: there is nothing that is printed).

Python outputs no error, and when I run the code in IPython, I notice that i is equivalent to to the very last element in the list "catdate", instead of listing the indices of "catdate" that are equivalent to the intersection values.

Any help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about python

Related posts about index