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
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
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
[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
"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
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
[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,
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
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