Python: get index of each item in list with duplicates -
this question has answer here:
- loop through list both content , index [duplicate] 6 answers
- accessing index in python 'for' loops 13 answers
how index of each item in list, including duplicates? far know python list.index give me first index of duplicated item, this.
registros = ["celda", "celda", "test", "celda", "celda", "celda"] 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 (as simple possible) desired output?:
0 celda 1 celda 2 test 3 celda 4 celda 5 celda
Comments
Post a Comment