From 65d4ea05d2b68df68305db82d4121246cfeb461e Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Wed, 16 Feb 2000 00:49:47 +0000 Subject: add flatten helper function --- Lib/compiler/misc.py | 11 +++++++++++ Tools/compiler/compiler/misc.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/Lib/compiler/misc.py b/Lib/compiler/misc.py index a281c10..dae42d4 100644 --- a/Lib/compiler/misc.py +++ b/Lib/compiler/misc.py @@ -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 = {} diff --git a/Tools/compiler/compiler/misc.py b/Tools/compiler/compiler/misc.py index a281c10..dae42d4 100644 --- a/Tools/compiler/compiler/misc.py +++ b/Tools/compiler/compiler/misc.py @@ -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 = {} -- cgit v0.12