move flatten and flattener into helpers

This commit is contained in:
Bryan Bishop
2013-09-01 15:57:02 -05:00
parent a1d9fd778d
commit f666fcb67d
2 changed files with 15 additions and 15 deletions

View File

@@ -6785,21 +6785,6 @@ def to_asm(some_object, use_asm_rules=False):
asm += "\n; " + hex(last_address)
return asm
def flattener(x):
"flattens a list of sublists into just one list (generator)"
try:
it = iter(x)
except TypeError:
yield x
else:
for i in it:
for j in flattener(i):
yield j
def flatten(x):
"flattens a list of sublists into just one list"
return list(flattener(x))
def get_dependencies_for(some_object, recompute=False, global_dependencies=set()):
"""
calculates which labels need to be satisfied for an object

View File

@@ -12,3 +12,18 @@ def grouper(some_list, count=2):
given: [1, 2, 3, 4]
returns: [[1, 2], [3, 4]]"""
return [some_list[i:i+count] for i in range(0, len(some_list), count)]
def flattener(x):
"flattens a list of sublists into just one list (generator)"
try:
it = iter(x)
except TypeError:
yield x
else:
for i in it:
for j in flattener(i):
yield j
def flatten(x):
"flattens a list of sublists into just one list"
return list(flattener(x))