I believe this question has been asked before, but I am not finding the link currently.
If you are trying to get more than one predicate and you only want to iterate once over the original generator, then you will have to use a simple for
loop.
evens = []
odds = []
for i in xrange(10):
if i % 2 == 0: evens.append(i)
else: odds.append(i)
As @dawg pointed out, the logic inside the loop can be made more concise using clever indexing.
for i in xrange(10):
(evens,odds)[i%2].append(i)