grep

yield items matching a pattern

Usage

  • <iterable> | grep(<test>…)
  • grep(<test>, <iterable>…)

test is:

  • a regular expression;
  • or a single argument function.

Examples

>>> from grapevine import *
>>> grep('a[rz]', ['foo', 'bar', 'baz']) | tuple
('bar', 'baz')
>>> xrange(-10, 10) | grep(lambda x: x % 7 == 1) | tuple
(-6, 1, 8)

See also