Why can't you assign to a list in a loop without enumerate?

Fredrik Lundh fredrik at pythonware.com
Wed Nov 1 10:29:07 EST 2006


Bjoern Schliessmann wrote:

>> define "it".
> 
> Sorry! I mean iterating over a list and having the list index
> available in the loop. Like:
> 
> for i, thing in enumerate(things):
>     pass

"enumerate" is the obviously right thing for this, sure.  but it's not 
necessarily the right thing for the OP's "I want to create a new list 
based on an existing list".  modifying the existing list is usually not 
the most efficient way to do that.

</F>




More information about the Python-list mailing list