diff --git a/scripts/json_array_to_list b/scripts/json_array_to_list new file mode 100755 index 0000000..8fb258c --- /dev/null +++ b/scripts/json_array_to_list @@ -0,0 +1,26 @@ +#!/bin/python3 +from pathlib import Path +import tempfile +import subprocess + +if __name__ == "__main__": + # set input_string to the contents of a temporary file opened with nano + f = tempfile.NamedTemporaryFile(mode='w+t', delete=False) + n = f.name + f.close() + subprocess.call(['nano', n]) + + with open(n, 'r') as f: + input_string = f.read() + Path(n).unlink() + + # Write your code here + input_string = input_string.strip().strip(',').strip('[').strip(']') + + def process_part(part: str) -> str: + part = part.strip() + quotation = '"' if part.startswith('"') and part.endswith('"') else "'" + return part.strip(quotation) + + input_string = ','.join(process_part(p) for p in input_string.split(',')) + print(input_string) \ No newline at end of file