F
Fernando Rodríguez
Hi,
While iterating through a list I'd like to know not just the current element,
but also its index. Is there a better way than this:
i = 0
newList = []
for element in aList:
newList.append((i, element))
i += 1
Is there a more elegant way of doing this with for? And with map()?
Thanks
While iterating through a list I'd like to know not just the current element,
but also its index. Is there a better way than this:
i = 0
newList = []
for element in aList:
newList.append((i, element))
i += 1
Is there a more elegant way of doing this with for? And with map()?
Thanks