coding utf-8 data def flat data res for element in data if isinstance

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# -*- coding: utf-8 -*-
data = [1,2,[3,4,[5,6]]]
def flat(data):
res = []
for element in data:
if isinstance(element,list):
res += flat(element)
else:
res.append(element)
return res
print flat(data)