<div dir="ltr"><div>A syntax that would work (which atm is a syntax error, and requires no new keyword) would be <br></div><div><br></div><div>    student_by_school = {school: [student] for school, student in student_school_list, grouped=True}<br></div><div><br></div><div>with grouped=True being a modifier on the dict comprehension so that at each iteration loop<br></div><div><br></div><div>current_dict[key] = value if key not in current_dict else current_dict[key] + value<br></div><div><br></div><div>This is an extremely borderline syntax (as it is perfectly legal to put **{'grouped': True} in a dict comprehension), but it works. <br></div><div>It even keeps the extremely important "should look like a template of the final object" property.<br></div><div><br></div><div>But it doesn't requires me to defines 2 lambda functions just to do the job of a comprehension.<br><br></div><div>-- <br></div><div>Nicolas Rolin<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-06-29 4:57 GMT+02:00 Michael Selik <span dir="ltr"><<a href="mailto:mike@selik.org" target="_blank">mike@selik.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div class="gmail_quote"><div dir="ltr">On Thu, Jun 28, 2018, 6:46 PM Nicolas Rolin <<a href="mailto:nicolas.rolin@tiime.fr" target="_blank">nicolas.rolin@tiime.fr</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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></div></div></div></div></blockquote></div><div><br></div></span><div>My intuition is no, it's not important enough to alter the syntax, despite being an important task.</div><span class=""><div><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>- In which case, is there a way to find a simple syntax that is not too confusing ?<br></div></div></div></div></blockquote></div><div><br></div></span><div>If you'd like to give it a shot, try to find something which is currently invalid syntax, but does not break compatibility. The latter criteria means no new keywords. The syntax should look nice as a single line with reasonably verbose variable names.</div><div><br>One issue is that Python code is mostly 1-dimensional, characters in a line, and you're trying to express something which is 2-dimensional, in a sense. There's only so much you can do without newlines and indentation.<br></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><p>--<b><br>Nicolas Rolin</b> | Data Scientist<br>+ 33 631992617 - nicolas<a href="mailto:prenom.nom@tiime.fr" rel="nofollow" target="_blank">.rolin@tiime.fr</a></p><p><span></span><span><font color="#888888"><img src="https://docs.google.com/uc?export=download&id=0B5gEmxojZz7NUklic0RTMDVXd0E&revid=0B5gEmxojZz7NYytTZzQ3Q2t6d0xYZGZVSkljV3RCNGxZRENVPQ" width="96" height="28"> </font></span><br><i>15 rue Auber, </i><i>75009 Paris</i><br><i><a href="http://www.tiime.fr" rel="nofollow" target="_blank">www.tiime.fr</a></i></p></div></div></div></div></div></div>
</div>