Vor jeder Innen Liste in einer großen Liste einen Index einfügen
Verfasst: Dienstag 9. Mai 2023, 14:11
Hallo,
ich hab folgende Liste:
[
[0, a, b, c],
[1, a, b, c],
[2, a, b, c],
[0, x, y, z],
[1, x, y, z],
[2, x, y, z],
...
]
Nun möchte ich folgendes:
[
[0, 0, a, b, c],
[1, 1, a, b, c],
[2, 2, a, b, c],
[3, 0, x, y, z],
[4, 1, x, y, z],
[5, 2, x, y, z],
...
]
Also einen eindeutigen Index am Anfang von jeder Innenliste.
Das hat nicht geklappt:
Auch bestbooks_list[0].insert(0, i) nicht. Wie geht das am besten? Danke
ich hab folgende Liste:
[
[0, a, b, c],
[1, a, b, c],
[2, a, b, c],
[0, x, y, z],
[1, x, y, z],
[2, x, y, z],
...
]
Nun möchte ich folgendes:
[
[0, 0, a, b, c],
[1, 1, a, b, c],
[2, 2, a, b, c],
[3, 0, x, y, z],
[4, 1, x, y, z],
[5, 2, x, y, z],
...
]
Also einen eindeutigen Index am Anfang von jeder Innenliste.
Das hat nicht geklappt:
Code: Alles auswählen
for i in range(len(bestbooks_list)):
print(i)
bestbooks_list.insert(0, i)
bestbooks_list