Skip to content

Commit 9976472

Browse files
authored
Merge pull request powerexploit#18 from liamplm/new-script-flat-list
add new script for making list flatten from JSON input (array)
2 parents 7d1ad1f + 629994d commit 9976472

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Scripts/flat_list.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy