Search code examples
pythonlistvectorindices

Grab the index numbers of a list which have been built by code


I wanted to compare two lists of vector elements and grab the equal elements of the lists and compose a 3rd list, I've already accomplished that.Now, I want to find out what are the index numbers of the elements grabbed from the 1st list. ex:

vectlist1 = [(0.25,0.65,0.33), (0.43,0.23,0.55), (0.56,0.8, 0.90), (0.34, 0.45, 0.67)]

... vectlist3 = [(0.43,0.23,0.55), (0.56,0.8, 0.90)]

vectlis1tindexnumbers = (1,2)

How do I do that plz? OBS: The elements are vectores, so in order for the vectors to be equal to another vector, all the three floats inside the two o them must be equal. I ommited the 2nd list in the example above, but it should have the same elements within it which were taken in order to compose the 3rd list.


Solution

  • Something like this should work:

    vectlis1tindexnumbers = [vectlist1.index(vector) for vector in vectlist3]
    print(vectlis1tindexnumbers)
    
    >>> [1, 2]