Split a list into two parts based on a filter?
rusi
rustompmody at gmail.com
Tue Jun 11 12:37:02 EDT 2013
On Jun 11, 6:48 pm, Fábio Santos <fabiosantos... at gmail.com> wrote:
>
> What I like so much about it is the .. if .. else .. Within the parenthesis
> and the append() call outside these parenthesis.
You can do this -- which does not mix up functional and imperative
styles badly and is as much a 2-liner as Roy's original.
new_songs, old_songs = [], []
for s in songs: (new_songs if s.is_new() else old_songs).append(s)
[Of course I would prefer a 3-liner where the body of the for is
indented :-) ]
More information about the Python-list
mailing list