<p dir="ltr"><br>
On 11 Jun 2013 07:47, "Peter Otten" <__<a href="mailto:peter__@web.de">peter__@web.de</a>> wrote:<br>
><br>
> Fábio Santos wrote:<br>
><br>
> > On 10 Jun 2013 23:54, "Roel Schroeven" <<a href="mailto:roel@roelschroeven.net">roel@roelschroeven.net</a>> wrote:<br>
> >><br>
> >> You could do something like:<br>
> >><br>
> >> new_songs, old_songs = [], []<br>
> >> [(new_songs if s.is_new() else old_songs).append(s) for s in songs]<br>
> >><br>
> >> But I'm not sure that that's any better than the long version.<br>
> ><br>
> > This is so beautiful!<br>
><br>
> It makes me cringe.<br>
><br>
> This code does spurious work to turn what is naturally written as a for loop<br>
> into a list comprehension that is thrown away immediately. I think I'd even<br>
> prefer this "gem"<br>
><br>
> >>> evens = []<br>
> >>> odds = [item for item in range(10) if item % 2 or evens.append(item)]<br>
> >>> evens, odds<br>
> ([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])<br>
><br>
> but if I have my way every side effect in a list comprehension should be<br>
> punished with an extra hour of bug-hunting ;)<br>
></p>
<p dir="ltr">What I like so much about it is the .. if .. else .. Within the parenthesis and the append() call outside these parenthesis.</p>
<p dir="ltr">I agree it would be best written as a for loop, to increase readability and avoid confusion. I always expect list comprehensions to be used as expressions, and its use as a (single-expression) statement is rather odd.</p>

<p dir="ltr">On 11 Jun 2013 07:52, "Jonas Geiregat" <<a href="mailto:jonas@geiregat.org">jonas@geiregat.org</a>> wrote:<br>
> I must disagree , this is unreadable and in my honor opinion not Pythonic at all.<br>
> I've learned it's always better to be explicit then implicit, and this snippet of code does a lot in an implicit way.<br>
></p>
<p dir="ltr">(Read above)</p>