Split a list into two parts based on a filter?

alex23 wuwei23 at gmail.com
Tue Jun 11 20:44:29 EDT 2013


On Jun 11, 9:08 am, Fábio Santos <fabiosantos... at gmail.com> wrote:
> On 10 Jun 2013 23:54, "Roel Schroeven" <r... at roelschroeven.net> wrote:
> > new_songs, old_songs = [], []
> > [(new_songs if s.is_new() else old_songs).append(s) for s in songs]
>
> This is so beautiful!

No, it's actually pretty terrible. It creates a list in order to
populate _two other lists_ and then throws away the one made by the
comprehension. There's nothing ugly about multiline for-loops.



More information about the Python-list mailing list