Python: Finding corresponding indices for an intersection of two lists

前端 未结 1 1087
时光说笑
时光说笑 2021-01-13 12:35

This is somewhat related to a question I asked not too long ago today. I am taking the intersection of two lists as follows:

    inter = set(NNSRCfile[\'date         


        
1条回答
  •  时光说笑
    2021-01-13 13:01

    I would create a dictionary to hold the original indices:

    ind_dict = dict((k,i) for i,k in enumerate(NNSRCfile['datetimenew']))
    

    Now, build your sets as before:

    inter = set(ind_dict).intersection(catdate)
    

    Now, to get a list of indices:

    indices = [ ind_dict[x] for x in inter ]
    

    0 讨论(0)
提交回复
热议问题