Kindly show me a better way to do it

superpollo utente at esempio.net
Sat May 8 16:56:17 EDT 2010


superpollo ha scritto:
> Oltmans ha scritto:
>> Hi, I've a list that looks like following
>>
>> a = [ [1,2,3,4], [5,6,7,8] ]
>>
>> Currently, I'm iterating through it like
>>
>> for i in [k for k in a]:
>>     for a in i:
> 
> i think you used te a identifier for two meanings...
> 
>>         print a
>>
>> but I was wondering if there is a shorter, more elegant way to do it?
> 
> 
> add = lambda a,b: a+b

or:

from operator import add


> for i in reduce(add,a):
>     print i



More information about the Python-list mailing list