Next / Previous / Contents / Shipman's homepage

5.8. Each: Require components in any order

pp.Each([p0, p1, ...])

This class returns a ParserElement that matches a given set of pieces, but the pieces may occur in any order. You may also construct this class using the “&” operator and the identity “Each([p0, p1, p2, ...]) == p0 & p1 & p2 & ...”. Here is an example: a pattern that requires a string of letters and a string of digits, but they may occur in either order.

>>> num=pp.Word(pp.nums)
>>> name=pp.Word(pp.alphas)
>>> nameNum = num & name
>>> print nameNum.parseString('Henry8')
['Henry', '8']
>>> print nameNum.parseString('16Christine')
['16', 'Christine']