Map with an extra parameter

ml1n emlyn at brizzle.com
Fri Sep 8 20:21:17 EDT 2006


bearophileHUGS at lycos.com wrote:
> This may be what you need:
>
> class foo:
>   def __init__(self, a, b):
>      self.a = a
>      self.b = b
>
> vars = [1,2,3,4,5,6]
> objects = [foo(a, 1) for a in vars]
>
>
> Note that in Python the new is expressed wit the () at the end:
>
> >   f = new foo()
>
> Bye,
> bearophile

(Not sure if this group likes top or bottom posts, sorry)
Thanks for the reply,
In the interests of speed my thinking was that using map would move the
loop out of Python and into C, is that the case when using list
comprehension?  I'd always thought it was just syntatic short hand for
a Python loop.

M.




More information about the Python-list mailing list