summaryrefslogtreecommitdiff
path: root/src/examples/groupUsingListAllMatches.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/groupUsingListAllMatches.py')
-rw-r--r--src/examples/groupUsingListAllMatches.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/examples/groupUsingListAllMatches.py b/src/examples/groupUsingListAllMatches.py
new file mode 100644
index 0000000..ca9e5ab
--- /dev/null
+++ b/src/examples/groupUsingListAllMatches.py
@@ -0,0 +1,16 @@
+#
+# A simple example showing the use of the implied listAllMatches=True for
+# results names with a trailing '*' character.
+#
+# This example performs work similar to itertools.groupby, but without
+# having to sort the input first.
+#
+from pyparsing import Word, ZeroOrMore, nums
+
+aExpr = Word("A", nums)
+bExpr = Word("B", nums)
+cExpr = Word("C", nums)
+grammar = ZeroOrMore(aExpr("A*") | bExpr("B*") | cExpr("C*"))
+
+results = grammar.parseString("A1 B1 A2 C1 B2 A3")
+print results.dump()