forked from powerexploit/Awesome-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat_list.py
More file actions
29 lines (22 loc) · 683 Bytes
/
Copy pathflat_list.py
File metadata and controls
29 lines (22 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/local/bin/python3
# return flat list from input list
import json
user_input = input('Enter a list with json format ...\n>')
try:
my_list = json.loads(user_input)
except json.decoder.JSONDecodeError:
print('invalid json input. unable to convert inout json to list !!!')
if not isinstance(my_list, list):
print('only list(array) are allowed !!!')
exit(1)
def flat(input_list):
result_list = []
for item in input_list:
if isinstance(item, list):
result_list.extend(flat(item))
else:
result_list.append(item)
return result_list
result = flat(my_list)
print('Input:', my_list)
print('Result:', result)