Skip to content

Commit b9dcd6c

Browse files
Create list_flatten.py
1 parent a71618f commit b9dcd6c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

list_flatten.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
a=[1,2,3,[4],[3,[4,5,6,[7]]],[8,9,[10],11]]
2+
3+
4+
5+
print(a)
6+
res=[]
7+
def flatten(element):
8+
if isinstance(element,int):
9+
res.append(element)
10+
else:
11+
for i in element:
12+
flatten(i)
13+
14+
for data in a:
15+
flatten(data)
16+
17+
print(res)
18+
19+
20+

0 commit comments

Comments
 (0)