Split a list into two parts based on a filter?
Serhiy Storchaka
storchaka at gmail.com
Tue Jun 11 11:27:04 EDT 2013
11.06.13 07:11, Roy Smith написав(ла):
> In article <mailman.2992.1370904643.3114.python-list at python.org>,
> Roel Schroeven <roel at roelschroeven.net> wrote:
>
>> new_songs, old_songs = [], []
>> [(new_songs if s.is_new() else old_songs).append(s) for s in songs]
>
> Thanks kind of neat, thanks.
>
> I'm trying to figure out what list gets created and discarded. I think
> it's [None] * len(songs).
It is the same as your klunky code, but consumes more memory.
More information about the Python-list
mailing list