Statement (un)equality ['LBBW': checked]

Holger Joukl Holger.Joukl at LBBW.de
Fri Feb 20 05:56:03 EST 2004


You are applying the map function to multiple lists here, _not_ to one list
consisting of
2-element-lists. this results in:
t = map(func, s1, s2, ..., sn) ==> t[i] = func(s1[i], s2[i], ....sn[i])
The number of arguments taken by the function must match the number of
lists given,
which is the case in your example.
See library doc (or Beazley´s essential reference, or any other decent
book).

E.g. it is not possible to do:
>>> map(lambda x,y: [y,x], [1,2],[3,4],[5,6])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: <lambda>() takes exactly 2 arguments (3 given)

but this is possible:
>>> [[y,x] for x,y in [1,2],[3,4],[5,6]]
[[2, 1], [4, 3], [6, 5]]
_________________________________

Holger Joukl
Landesbank Baden-Württemberg
1651 Financial Markets Technologies
fon +49 (711) 124 - 7078
fax +49 (711) 124 - 3759
_________________________________

__________________


castle:/home/adam>python
Python 2.3 (#3, Aug  4 2003, 16:43:33)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> [[y,x] for x,y in [1,2],[3,4]]
[[2, 1], [4, 3]]
>>> map(lambda x,y: [y,x], [1,2],[3,4])
[[3, 1], [4, 2]]
>>>
Why there is a difference? How to make the same thing like in map
statement?
Regards
        Adam Przybyla
--
 http://mail.python.org/mailman/listinfo/python-list

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.







More information about the Python-list mailing list