-1

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.

AAA Yerus
  • 31
  • 4
  • You want the corresponding index in the first list of the tuples in the second one, is that correct? What isn't working, what have you tried? – AMC Dec 24 '19 at 02:24

1 Answers1

0

Something like this should work:

vectlis1tindexnumbers = [vectlist1.index(vector) for vector in vectlist3]
print(vectlis1tindexnumbers)

>>> [1, 2]
marcos
  • 4,473
  • 1
  • 10
  • 24
  • Thanks! Is there a way to do this whitout loops? Perhaps by grabbing the indices yet when we extract the values from the vectlist1 for the first time? – AAA Yerus Dec 24 '19 at 04:34
  • My dev for extracting had been this one : https://stackoverflow.com/questions/59106106/compare-vector-lists – AAA Yerus Dec 24 '19 at 04:35
  • I think it's best if you create another question with what you want. Is this answer correct in it's original intention? @AAAYerus – marcos Dec 24 '19 at 04:48
  • yes it is! Thanks! I wonder if that is much more difficult to get the indices from the start instead of with loop. – AAA Yerus Dec 24 '19 at 05:10
  • i checked how the other answer solved it using `sets`, so you would have to code it with manual `for`s in order to get everything in one iteration. so my suggestion is don't, my answer only adds one line of code, so mix both answers. but it's definitely possible. @AAAYerus – marcos Dec 24 '19 at 05:15