How to implement function like this?
Loic Mahe
loic.mahe at nospam.fr
Tue Oct 23 06:45:30 EDT 2007
Marc 'BlackJack' Rintsch a écrit :
> On Tue, 23 Oct 2007 11:48:08 +0200, Loic Mahe wrote:
>
>> even shorter:
>>
>> def funcA(tarray):
>> s = min(len(tarray), 3)
>> return [2, 3, 4][0:s] + [e for e in funcB(3-s)[0:3-s]]
>
> Why the list comprehension!?
>
> Ciao,
> Marc 'Blackjack' Rintsch
sorry I just read too fast
and thought he worked with lists ...
anyway 'e for e in' and so list comprehension was useless here
def funcA(tarray):
s = min(len(tarray), 3)
return (2, 3, 4,)[0:s] + funcB(3-s)[0:3-s]
this is ok if funcB(...) returns a tuple ...
if it returns a list just add: tuple(funcB(...))
note: list comprehension transforms a tuple into a list
More information about the Python-list
mailing list