mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
add flatten helper function
This commit is contained in:
parent
4f6bcd80fc
commit
65d4ea05d2
2 changed files with 22 additions and 0 deletions
|
@ -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:
|
class Set:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.elts = {}
|
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:
|
class Set:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.elts = {}
|
self.elts = {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue