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

Chris Angelico rosuav at gmail.com
Tue Mar 25 00:07:01 CET 2014

On Tue, Mar 25, 2014 at 9:58 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Tue, 25 Mar 2014 06:22:28 +1100, Chris Angelico wrote:
>> Aside: You'll often hear people talking about "map-reduce" with big
>> data. Python supports that. Look!
>>>>> map.__reduce__
>> <method '__reduce__' of 'map' objects>
>> Oh wait, that's nothing to do with reduce()...
>> *ducks for cover*
> Ha ha, very funny :-P
> http://code.activestate.com/recipes/577676-dirt-simple-mapreduce/

That looks like a more serious map/reduce example. Mine came from a
double-take when I was looking at help(map) for some reason; there's a
__round__ magic method that helps define the round() function, there's
__abs__ for abs(), there's __str__ for str()... look, there's a
__reduce__ - it must be to help define reduce()! :)


More information about the Python-list mailing list