Map with an extra parameter

Simon Forman rogue_pedro at yahoo.com
Sat Sep 9 03:34:57 EDT 2006


ml1n wrote:
> 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.

Your thinking is correct. :-)   Check out
http://groups.google.ca/group/comp.lang.python/msg/7a56cf1a052b9c5d
wherein Fredrik Lundh shows the difference by bytecode disassembly.

Peace,
~Simon

P.S. Bottom posts.




More information about the Python-list mailing list