From python-list Wed Jul 06 19:16:40 2005 From: Stian =?iso-8859-1?Q?S=F8iland?= Date: Wed, 06 Jul 2005 19:16:40 +0000 To: python-list Subject: Re: map/filter/reduce/lambda opinions and background Message-Id: <20050706191640.GX12095 () itea ! ntnu ! no> X-MARC-Message: https://marc.info/?l=python-list&m=112067741409784 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