0

How do I get the index of each item in a list, including duplicates? As far as I know python list.index will only give me the first index of a duplicated item, like this.

registros = ["Celda", "Celda", "Test", "Celda", "Celda", "Celda"]
    for item in registros:
        index_found = registros.index(item)
        print(str(index_found) + " " + dato)

Outputs:

0 Celda
0 Celda
2 Test
0 Celda
0 Celda
0 Celda

So how do I do (as simple as possible) to get this desired output?:

0 Celda
1 Celda
2 Test
3 Celda
4 Celda
5 Celda
Saelyth
  • 1,504
  • 1
  • 21
  • 36

0 Answers0