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

Terry Reedy tjreedy at udel.edu
Mon Mar 24 21:04:41 EDT 2014


On 3/24/2014 7:07 PM, Chris Angelico wrote:
> 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()! :)

That was my first think also. I believe __pickle__ or __unpickle__ would 
have been more appropriate.

-- 
Terry Jan Reedy




More information about the Python-list mailing list