c[:]()
Warren Stringer
warren at muse.com
Thu May 31 11:44:16 EDT 2007
> >
> > But that still isn't as simple or as direct as:
> >
> > c[:]()
>
> Why do you always use a _copy_ of c in your examples? As long
> as you're wishing, why not just
>
> c()
Oh hey Grant, yes, I misunderstood your question for a bit. I thought you
meant the difference between List comprehension [...] and generator
expressions (...) where the first returns the whole list and the second
iterates the whole list.
But, yes, good point if I was only using [:]. For more expressiveness, I
could using the alternative, to the example in my reply to Douglas
def beauty(judge): ...
As an alternative to my reply to Douglas ... and is more cell phone
friendly, due to lack of cumbersome [], which I just mentioned to Mikael,
who came up with an really cool [] solution ... hmmm ...
Translating Mikael's solution to the original c[:]() with some tweaks:
class do(list):
def __call__(self,*args,**kwargs):
return [f(*args,**kwargs) for f in self]
def a(): print 'a called'
def b(): print 'b called'
c = [a,b]
do(c[:])() # close but with cell phone gnarly []
do(c)() # woo hoo!
In recalling Marc's reply about a cool one liner, such a statement
translates in English, as "do everything in c" <insert evil laughter>
Cheers,
\~/
More information about the Python-list
mailing list