for loop without variable

Ryan Ginstrom software at ginstrom.com
Thu Jan 10 22:52:56 EST 2008


> On Behalf Of Marty
> I recently faced a similar issue doing something like this:
> 
>      data_out = []
>      for i in range(len(data_in)):
>      	data_out.append([])
> 
> This caused me to wonder why Python does not have a "foreach" 
> statement (and also why has it not come up in this thread)?  
> I realize the topic has probably been beaten to death in 
> earlier thread(s), but does anyone have the short answer?

data_out = [[] for item in data_in]

Regards,
Ryan Ginstrom




More information about the Python-list mailing list