0

Below is my code which is finding a common element.

but I actually want to get the index of it as well, can someone tell me how to do that?

a1=[11,10,21,23,24,25,128,12]
b1=[1,2,11,12,21]
c=[]
index_a1=[]
index_b1=[]
for element in a1:
      if element in b1:
          c.append(element)
c

i want index_b1(expected result) like [2,3,4], and index_a1 as well if possible.

thanks

Coder
  • 1,129
  • 10
  • 24

1 Answers1

2

You can use enumerate() and list.index().

for idx, element in enumerate(a1):
    if element in b1:
        c.append(element)
        index_a1.append(idx)
        index_b1.append(b1.index(element))
Unmitigated
  • 76,500
  • 11
  • 62
  • 80