We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a7a72e commit 629994dCopy full SHA for 629994d
Scripts/flat_list.py
@@ -0,0 +1,29 @@
1
+#!/usr/local/bin/python3
2
+# return flat list from input list
3
+
4
+import json
5
6
+user_input = input('Enter a list with json format ...\n>')
7
8
+try:
9
+ my_list = json.loads(user_input)
10
+except json.decoder.JSONDecodeError:
11
+ print('invalid json input. unable to convert inout json to list !!!')
12
13
+if not isinstance(my_list, list):
14
+ print('only list(array) are allowed !!!')
15
+ exit(1)
16
17
+def flat(input_list):
18
+ result_list = []
19
+ for item in input_list:
20
+ if isinstance(item, list):
21
+ result_list.extend(flat(item))
22
+ else:
23
+ result_list.append(item)
24
+ return result_list
25
26
+result = flat(my_list)
27
+print('Input:', my_list)
28
+print('Result:', result)
29
0 commit comments