What's BETTER for MAP function?

Zaur Shibzukhov sz at zmail.ru
Wed Feb 9 18:39:42 CET 2000

What's BETTER for MAP function?

I have a function func(X, Y).

I want to do:

R = []
X = ....
for Y in Ys:
   R.append(func(X, Y))

I can use map function with lambda expression:

map(lambda y, x=X: func(x,y), Ys)

and without lambda:

map(func, Ys, len(Ys)*[X])

I tried:

class TConst:
   def __init__(self, v, n):
      self.v = v
      self.n = n
   def __getitem__(self, i):
      if 0 <= i < self.n:
         return self.v
         raise IndexError
   def __len__(self):
      return self.n
and write:
map(func, Ys, TConst(X, len(Ys)))

Note, that sequence Ys is not small.
All this solutions are not good for my goals.

I think that it is better for perfomance to implement object
TConst in C.
Another way?

What think Python guru?

Zaur Shibzoukhov

Get Your e-mail at http://zmail.ru

More information about the Python-list mailing list