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 01:28:40 CET 2014


On Tue, Mar 25, 2014 at 11:16 AM, Mark H Harris <harrismh777 at gmail.com> wrote:
> On 3/24/14 7:11 PM, Chris Angelico wrote:
>>
>> On Tue, Mar 25, 2014 at 10:56 AM, Mark H Harris<harrismh777 at gmail.com>
>> wrote:
>>>
>>> What is needed is the explicit closure "grab" recommended by ChrisA.
>>
>>
>> Which does work. You do know why, right?
>
>
> Sure.  ... but again, that's not the point. The point is NOT can you explain
> why it works, the point is that as a lambda construct it is NOT clear why it
> works, and because the construct does not match what lambda users might
> expect (naturally) there are *constant* questions about it.
>
> So, again, I'll restate that the community might consider (over time)
> whether the confusion created by lambda in python is worth the time and
> trouble to maintain the construct in the language. Is the value add worth
> the cost of confusion. I don't think so; others are bound to disagree.

Pure functional programming, from what I understand, doesn't *have*
variables other than function arguments. So the way to implement "x =
1" is to call a subfunction with an argument of 1, which is referred
to as x. (Am I right so far?) In that case, the default argument trick
is exactly the right way to implement that in Python.

ChrisA



More information about the Python-list mailing list