Re: Map with an extra parameter

2006-09-09 Thread Peter Otten
ml1n wrote: > I'm not really sure how to explain this so maybe some example code is > best. This code makes a list of objects by taking a list of ints and > combining them with a constant: > > class foo: > def __init__(self): > self.a = 0 > self.b = 0 > > def func(a,b): > f = new

Re: Map with an extra parameter

2006-09-09 Thread Simon Forman
ml1n wrote: > [EMAIL PROTECTED] 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 th

Re: Map with an extra parameter

2006-09-08 Thread bearophileHUGS
ml1n: > Looks like someone already did: > http://mail.python.org/pipermail/python-list/2005-January/259870.html Don't belive too much in such general timings. Time your specific code when you think you need a true answer. Timing Python code is very easy and fast, and sometimes results are surprisi

Re: Map with an extra parameter

2006-09-08 Thread ml1n
[EMAIL PROTECTED] wrote: > ml1n wrote: > > 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. > > In Python the fast

Re: Map with an extra parameter

2006-09-08 Thread Paul Rubin
"ml1n" <[EMAIL PROTECTED]> writes: > 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. Best to run benchmarks, but I don

Re: Map with an extra parameter

2006-09-08 Thread bearophileHUGS
ml1n wrote: > 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. In Python the faster things are often the most simple. Y

Re: Map with an extra parameter

2006-09-08 Thread ml1n
[EMAIL PROTECTED] 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,

Re: Map with an extra parameter

2006-09-08 Thread bearophileHUGS
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 -- http://mail.python.org/mailman/list

Map with an extra parameter

2006-09-08 Thread ml1n
Hi, I'm not really sure how to explain this so maybe some example code is best. This code makes a list of objects by taking a list of ints and combining them with a constant: class foo: def __init__(self): self.a = 0 self.b = 0 def func(a,b): f = new foo() f.a = a f.b = b ret