Kindly show me a better way to do it
Jean-Michel Pichavant
jeanmichel at sequans.com
Mon May 10 07:30:00 EDT 2010
Oltmans wrote:
> On May 9, 1:53 am, superpollo <ute... at esempio.net> wrote:
>
>
>> add = lambda a,b: a+b
>> for i in reduce(add,a):
>> print i
>>
>
> This is very neat. Thank you. Sounds like magic to me. Can you please
> explain how does that work? Many thanks again.
>
>
shorter <> nicer IMO.
Those alternatives are interesting from a tech point of view, but
nothing can beat the purity of a vintage 'for' loop with *meaningful names*.
salads = [['apple', 'banana'], ['apple', 'lemon', 'kiwi']]
ingredients = []
for salad in salads:
for fruit in salad:
ingredients.append(fruit)
print 'Remember to buy %s' % ingredients
Lame & effective (1st adjective is irrelevant outside a geek contest)
JM
More information about the Python-list
mailing list