Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

Steven D'Aprano steve at pearwood.info
Tue Mar 25 02:20:20 EDT 2014


On Mon, 24 Mar 2014 17:58:11 -0600, Ian Kelly wrote:

> On Mon, Mar 24, 2014 at 3:43 PM, Mark H Harris <harrismh777 at gmail.com>
> wrote:
>>    Aside from the sin of spelling out "lambda,"
>>       should be   ( \x y -> x + y ) a b )  but, neither here nor
>>       there...
> 
> Well no, it *should* be λx y . x + y but apparently some people don't
> have that character on their keyboards, so it gets written as lambda or
> \ instead. 


Holy cow! Is that where the Haskell syntax comes from?

I never would have guessed in a million years that backslash \ was meant 
to be an ASCII-ified version of lambda. What a stupid idea that is. 
Writing "lambda" out in full is much more sensible.

> Personally I dislike the \ style; it doesn't really resemble
> a λ that closely, and to me the backslash denotes escape sequences and
> set differences.  Nor is Python alone in spelling out lambda: Scheme and
> Common Lisp spell it the same way. As far as I know the \ for λ is
> unique to Haskell.

At least they don't spell it "fun". 



-- 
Steven



More information about the Python-list mailing list