c[:]()
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sun Jun 3 10:44:53 EDT 2007
In <1180878080.630213.258230 at q75g2000hsh.googlegroups.com>,
Stebanoid at gmail.com wrote:
> On 30 , 22:48, "Warren Stringer" <war... at muse.com> wrote:
>> I want to call every object in a tupple, like so:
>>
>> #------------------------------------------
>> def a: print 'a'
>> def b: print 'b'
>> c = (a,b)
>>
>> >>>c[:]() # i wanna
>>
>> TypeError: 'tupple' object is not callable
>>
>> >>>c[0]() # expected
>> a
>> >>>c[:][0] # huh?
>> a
>> >>> [i() for i in c] # too long and ...huh?
>>
>> a
>> b
>> [None,None]
>> #------------------------------------------
>>
>> bla-bla-bla......
>
>
> you can write:
>>>> map(lambda x: x(), c)
>
> I think that it is good idea to use "map()" function for doing
> somethimg with each element of a sequence, if the order of a actions
> not important.
>
> it is easy to read and understandable.
And has the same issue as a list comprehension if all you want is the side
effect of the calls: a useless temporary list full of `None`\s is build.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list