[Python-ideas] Allow a group by operation for dict comprehension
nicolas.rolin at tiime.fr
Thu Jun 28 21:45:50 EDT 2018
2018-06-28 22:34 GMT+02:00 David Mertz <mertz at gnosis.cx>:
> I agree with these recommendations. There are excellent 3rd party tools
> that do what you want. This is way too much to try to shoehorn into a
There are actually no 3rd party tools that can "do what I want", because if
I wanted to have a function to do a group by, I would have taken the 5
minutes and 7 lines necessary to do so (or don't use a function and do my 3
My main point is that comprehensions in python are very powerful and you
can do pretty much any basic data manipulation that you want with it EXCEPT
when you want to "split" a list in sublists, in which case you have either
to use functions or a for loop.
You can note that with list comprehension you can flatten an iterable (from
sublists to a single list) with the [a for b in c for a in b] syntax, but
doing the inverse operation is impossible.
The questions I should have asked In my original post was :
- Is splitting lists into sublists (by grouping elements) a high level
enough construction to be worthy of a nice integration in the comprehension
- In which case, is there a way to find a simple syntax that is not too
My personal answer would be respectively "yes" and "maybe I don't know".
I was hoping to have some views on the topic, and it seemed to have a bit
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas