usage of reduce

SC Zhong sai at dft.chem.cuhk.edu.hk
Tue May 8 02:04:32 EDT 2001


I am using version 1.5.2
would somebody tell me why the following does not work.

>>> z
[(1,5),(2,6),(3,7)]

>>> reduce(lambda x,y: x[1]+y[1], z)

Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 1, in <lambda>
TypeError: unsubscriptable object

however for map the variable for lambda is subscriptable
>>> map(lambda x: x[0],z)
[1,2,3]

thanks in advance
--
Zhong SC





More information about the Python-list mailing list