[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: map/filter/reduce/lambda opinions and background
From: Stian =?iso-8859-1?Q?S=F8iland?= <stian () soiland ! no>
Date: 2005-07-06 19:16:40
Message-ID: 20050706191640.GX12095 () itea ! ntnu ! no
[Download RAW message or body]
On 2005-07-06 07:00:04, Steven D'Aprano wrote:
> map(lambda x: if x == 0: 1; else: math.sin(x)/x,
> myList)
And now for the "readable" list comprehension version:
[x==0 and 1 or math.sin(x)/x for x in myList]
Now even though I'm into the short-circuiting of and-or and even
occasionally have used such masturbation techniques as this, I don't
think it qualifies as pythonic.
If it was me, I would probably even have written:
[x and math.sin(x)/x or 1 for x in myList]
--
Stian Søiland Work toward win-win situation. Win-lose
Trondheim, Norway is where you win and the other lose.
http://soiland.no/ Lose-lose and lose-win are left as an
exercise to the reader. [Limoncelli/Hogan]
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic