c[:]()

Stebanoid at gmail.com Stebanoid at gmail.com
Sun Jun 3 15:41:20 CEST 2007


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.

P.S. sorry my bad English




More information about the Python-list mailing list