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

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Mar 24 15:13:13 EDT 2014


On 24/03/2014 18:58, Mark H Harris wrote:
> On 3/24/14 4:58 AM, Mark Lawrence wrote:
>> Where do you get reduce from if it's not in the standard library?
>
>     That was "a" proposal for 3000. Its there, but its not on the
> built-ins; ie., you have to import it.  The confusion: why reduce, why
> not filter, nor map?  {rhetorical}

So it is in the standard library then.  And I'm not confused, seeing 
this must have been decided years ago as Python 3 was released some five 
years ago.

>
>> As for lambda I've no real interest in it, other than when copying
>> examples
>> where it's used to (say) provide a key function.
>>
>
> This is one of my main points to Steven. In my experience "most" people
> do not intend to use lambda for anything; they are trying to sort this
> or that and don't quite know how to get the key right and some helpful
> somebody gives them a key=lambda yadda yadda .  They use it, and it
> works, but they are scratching their head saying to themselves, "what it
> that, how does it work, how can I understand it and on and on".

More fool them, I write Python as I let it take away the head 
scratching, not add to it.  If I wanted to start head scratching maybe 
I'd go and investigate what line 247 of gcmodule.c does, but funnily 
enough I've never been there, and don't intend starting now.

>
> That is what we mean by confusing. Or another really great example is
> this thread. Somebody asks about a language feature and somebody else
> helpfully answers the question by providing them with a similar lambda!!

One of the joys of this list from my POV, YMMV.

>
> Its the programmer's equivalent of explanation by reference to a more
> complicated analogy; which leaves the OP left with, "Thanks for all the
> responses".
>
> marcus
>
> PS  You are absolutely right, all the expanding double spaces become
> very annoying when viewed on Thunderbird; it is exasperating, genuinely.
>

Yep, but like I said the situation has improved, partly thanks to the 
guys who improved the words on the wiki showing how to successfuly use 
gg.  Thanks fellas :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com





More information about the Python-list mailing list