B
bernhard.voigt
Hi,
is there is a neat way to select items from an iterable based on
predicates stored in another iterable without zipping? I can do
something like this:
import itertools
foo = range(10)
# select even numbers
bar = map(lambda i: i%2, foo)
foobarselected = itertools.ifilterfalse(lambda t: t[0], itertools.izip
(bar,foo))
# for simplicity I want to work with the single item list, not the
zipped one
fooselected = list(t[1] for t in foobarselected)
However, it would be nice to have a function combining the last two
instructions. Something like
itertools.ifilterother(bar, foo) -> yield iterator with items from foo
where bar is true
Thanks! Bernhard
is there is a neat way to select items from an iterable based on
predicates stored in another iterable without zipping? I can do
something like this:
import itertools
foo = range(10)
# select even numbers
bar = map(lambda i: i%2, foo)
foobarselected = itertools.ifilterfalse(lambda t: t[0], itertools.izip
(bar,foo))
# for simplicity I want to work with the single item list, not the
zipped one
fooselected = list(t[1] for t in foobarselected)
However, it would be nice to have a function combining the last two
instructions. Something like
itertools.ifilterother(bar, foo) -> yield iterator with items from foo
where bar is true
Thanks! Bernhard