Say I have a list of lists
L3 = [3, 4, 5]
L2 = [2, L3, 6]
L1 = [1, L2, 7]
Whats the best "Python"-ish way to print L1 without its inner lists showing as lists? (or how to copy all values to a new list of integers)
Say I have a list of lists
L3 = [3, 4, 5]
L2 = [2, L3, 6]
L1 = [1, L2, 7]
Whats the best "Python"-ish way to print L1 without its inner lists showing as lists? (or how to copy all values to a new list of integers)
here a function convert a nesting list to flat list
L3 = [3, 4, 5]
L2 = [2, L3, 6]
L1 = [1, L2, 7]
def flat_list(l):
result = []
for item in l:
if isinstance(item,list):
result.extend(flat_list(item))
else:
result.append(item)
return result
print flat_list(L1)
#print [1, 2, 3, 4, 5, 6, 7]