Map with an extra parameter
ml1n
emlyn at brizzle.com
Fri Sep 8 19:53:45 EDT 2006
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
return f
constants = [1]*6
vars = [1,2,3,4,5,6]
objects = map(func,vars,constants)
In the real world I need to do this as quick as possible (without
resorting to c) and there are several constants. (The constant is only
constant to each list so I can't make it a default argument to func.)
My question is, can anyone think of a way to do this efficiently
without having to use the `dummy` list of constants and would it be
quicker?
M.
More information about the Python-list
mailing list