@@ -474,19 +474,17 @@ representation to be ``['variable_name']``. A simple recursive function can
474474implement the pattern matching, returning a Boolean and a dictionary of variable
475475name to value mappings. (See file :file: `example.py `.) ::
476476
477- from types import ListType, TupleType
478-
479477 def match(pattern, data, vars=None):
480478 if vars is None:
481479 vars = {}
482- if type (pattern) is ListType :
480+ if isinstance (pattern, list) :
483481 vars[pattern[0]] = data
484- return 1 , vars
485- if type (pattern) is not TupleType :
482+ return True , vars
483+ if not instance (pattern, tuple) :
486484 return (pattern == data), vars
487485 if len(data) != len(pattern):
488- return 0 , vars
489- for pattern, data in map(None, pattern, data):
486+ return False , vars
487+ for pattern, data in zip( pattern, data):
490488 same, vars = match(pattern, data, vars)
491489 if not same:
492490 break
@@ -528,7 +526,7 @@ docstring from the parse tree created previously is easy::
528526
529527 >>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
530528 >>> found
531- 1
529+ True
532530 >>> vars
533531 {'docstring': '"""Some documentation.\n"""'}
534532
0 commit comments