<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-06-28 22:34 GMT+02:00 David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>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 comprehension.</div></div></blockquote><div> </div><div>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 liner).<br></div><div><br></div><div>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.<br></div><div>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. <br></div><div><br></div><div>The questions I should have asked In my original post was :<br>- Is splitting lists into sublists (by grouping elements) a high level enough construction to be worthy of a nice integration in the comprehension syntax ? <br>- In which case, is there a way to find a simple syntax that is not too confusing ?<br></div><div><br>My personal answer would be respectively "yes" and "maybe I don't know".<br></div><div>I was hoping to have some views on the topic, and it seemed to have a bit sidetracked :)<br><br>-- <br></div><div>Nicolas Rolin<br></div><div><br></div><br></div></div></div>