[Tutor] Python Cookbook
Yigal Duppen
yduppen@xs4all.nl
Mon, 26 Aug 2002 16:46:31 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> But what -is- the problem that some people have with lambda? (You
> mention that you don't have a problem with it, but that implies that
> others do.)
Most people favoring lambda have experience in Functional Programming, Lisp
and/or lambda calculus; people disliking it don't. To them, it probably looks
obscure.
> One last question -- in your final example above, you have an "if"
> statement FOLLOWING the "main" part of the list comprehension. Is this
> a normal Python construction or something that is allowed for list
> comprehensions only? I have seen that sort of construction in Perl:
No, the trailing if is only allowed in LCs. Luckily. Furthermore, in LCs the
if _must_ be trailing; for example, the following is illegal:
[ x if x % 2 == 0 for x in [1,2,3]]
otoh, the following is legal:
[ x for x in [1, 2, 3, 4] if x % 2 == 0 and x < 4 ]
> print "Correct" if ($correct);
Indeed one of the more horrible examples from Perl ;)
YDD
- --
http://www.xs4all.nl/~yduppen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9aj9HLsKMuCf5EdwRAm/rAJ4iZBZZc4RkIbd/KFFPMgyQnwG90QCgpGBB
Flm6MUe7uIKu+zaTxrsXJQw=
=OoD1
-----END PGP SIGNATURE-----