diff --git a/advanced-iterators.html b/advanced-iterators.html index 0e72bc0..a119e7d 100644 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -82,14 +82,18 @@ if __name__ == '__main__':

Finding all occurrences of a pattern

-

FIXME +

The first thing this alphametics solver does is find all the letters (A–Z) in the puzzle.

 >>> import re
->>> re.findall('[A-Z]+', 'SEND + MORE == MONEY')
+>>> re.findall('[0-9]+', '16 2-by-4s in rows of 8')  
+['16', '2', '4', '8']
+>>> re.findall('[A-Z]+', 'SEND + MORE == MONEY')     
 ['SEND', 'MORE', 'MONEY']
- -

FIXME +

    +
  1. The re module is Python's implementation of regular expressions. It has a nifty function called findall() which takes a regular expression pattern and a string, and finds all occurrences of the pattern within the string. In this case, the pattern matches sequences of numbers. The findall() function returns a list of all the substrings that matched the pattern. +
  2. Here the regular expression pattern matches sequences of letters. Again, the return value is a list, and each item in the list is a string that matched the regular expression pattern. +

Finding the unique items in a sequence