mirror of https://github.com/python/cpython.git
add flatten helper function
This commit is contained in:
parent
4f6bcd80fc
commit
65d4ea05d2
|
@ -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 = {}
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in New Issue