MCPcopy Create free account
hub / github.com/ActiveState/code / flattenlist

Function flattenlist

recipes/Python/577250_Flatten_a_list_/recipe-577250.py:1–23  ·  view source on GitHub ↗
(L)

Source from the content-addressed store, hash-verified

1 def flattenlist(L):
2 import types
3 WhiteTypes = ('StringType', 'UnicodeType', 'StringTypes', 'ListType',
4 'ObjectType', 'TupleType')
5 BlackTypes= tuple( [getattr(types, x) for x in dir(types)
6 if not x.startswith('_')
7 and x not in whites] )
8
9 tmp = []
10 def core(L):
11 if not hasattr(L,'__iter__'):
12 return [L]
13 else :
14 for i in L:
15 if isinstance(i,BlackTypes):
16 tmp.append(i)
17 continue
18 if type(i) == type(str()):
19 tmp.append(i)
20 else:
21 core(i)
22 return tmp
23 return core(L)
24
25
26

Callers 1

recipe-577250.pyFile · 0.85

Calls 3

dirFunction · 0.85
coreFunction · 0.85
startswithMethod · 0.80

Tested by

no test coverage detected