I have a list of words.
mylist = ["aus","ausser","bei","mit","noch","seit","von","zu"]
I want to turn each element in the list into a sublist and add to each a number so that each entry is indexed. So it should output
[[1, 'aus'], [2, 'ausser'], [3, 'bei'], [4, 'mit'], [5, 'noch'], [6, 'seit'], [7, 'von'], [8, 'zu']]
I know how to do such a thing with a while loop
mylist = ["aus","ausser","bei","mit","noch","seit","von","zu","aus","ausser","bei","mit","noch","seit","von","zu","aus","ausser","bei","mit","noch","seit","von","zu"]
mylist2
i=0
while i <= 10:
mylist2.append([i,mylist[i]])
i = i +1
print(mylist2)
But I want to use the following kind of structure with a for-loop:
mylist = ["aus","ausser","bei","mit","noch","seit","von","zu"]
outlist =[[1,word] for word in mylist]
print(outlist)
I'm not sure how to do that with a for-loop. Can someone explain how to do this?
list(enumerate(mylist, 1))