Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
Dan Stromberg
drsalists at gmail.com
Thu Mar 27 19:45:19 EDT 2014
More information about the Python-list mailing list
Thu Mar 27 19:45:19 EDT 2014
- Previous message (by thread): Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
- Next message (by thread): How to flatten a list of lists was (Explanation of this Python language feature?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Mar 21, 2014 at 1:42 PM, vasudevram <vasudevram at gmail.com> wrote: > Can anyone - maybe one of the Python language core team, or someone with knowledge of the internals of Python - can explain why this code works, and whether the different occurrences of the name x in the expression, are in different scopes or not? : > > x = [[1,2], [3,4], [5,6]] > [x for x in x for x in x] I'll give this +1 for playfulness, and -2 for lack of clarity. I hope no one thinks this sort of thing is good to do in real-life code.
- Previous message (by thread): Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
- Next message (by thread): How to flatten a list of lists was (Explanation of this Python language feature?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list