I have a list of objects from which I have filtered out those that have a particular value in a single attribute:
import itertools
iterator = itertools.ifilter(lambda record: record.outcome==1, list)
The iterator has now all objects with outcome = 1
However, they now differ in the value of another attribute order=X
I would like to partition the iterator in two: one for those objects whose order = 1
and another one for those with order > 1
Is there a another way than looping over all elements and adding them to one of the two lists / a list comprehension?
Say I have a list l
with obj1,obj2,obj3
as content where obj1.order=1
, obj2.order=2
and obj3.order=3
I would like to yield a # containing obj1
and b # containing obj2 & obj3
Preferably, I would like to have two other iterators so that I can do with the partial lists whatever I would like to do!
I was thinking about itertools.groupby
but as my variable order=X
has a number of possible values, it would give me more than two sub-iterators!