add flatten helper function

This commit is contained in:
Jeremy Hylton 2000-02-16 00:49:47 +00:00
parent 4f6bcd80fc
commit 65d4ea05d2
2 changed files with 22 additions and 0 deletions

View File

@ -1,3 +1,14 @@
import types
def flatten(tup):
elts = []
for elt in tup:
if type(elt) == types.TupleType:
elts = elts + flatten(elt)
else:
elts.append(elt)
return elts
class Set:
def __init__(self):
self.elts = {}

View File

@ -1,3 +1,14 @@
import types
def flatten(tup):
elts = []
for elt in tup:
if type(elt) == types.TupleType:
elts = elts + flatten(elt)
else:
elts.append(elt)
return elts
class Set:
def __init__(self):
self.elts = {}