From 52becb890925154652f51e783ca5021cd1e7908a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 22 Oct 2023 17:35:07 +0200 Subject: [PATCH] split_and_flat: add --- split_and_flat.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 split_and_flat.py diff --git a/split_and_flat.py b/split_and_flat.py new file mode 100644 index 0000000..1de70ea --- /dev/null +++ b/split_and_flat.py @@ -0,0 +1,38 @@ +import sys + + +def split_and_flat(input_string): + if "\n" in input_string: + _without_newlines = input_string.split("\n") + _without_empty = filter(lambda x: x != "", _without_newlines) + input_string = ",".join(_without_empty) + # Split the input string on commas + comma_split = input_string.split(",") + + # Initialize an empty flat list + flat_list = [] + + # Iterate through the comma-separated values + for item in comma_split: + # Split each item on dashes + dash_split = item.split("-") + + # Extend the flat list with the dash-separated values + flat_list.extend([value.strip().replace("\n", "") for value in dash_split]) + + map(lambda x: x.strip(), flat_list) + return ",".join(flat_list) + + +if __name__ == "__main__": + # Check if a single command-line argument is provided + if len(sys.argv) != 2: + print("Usage: python split_and_flat.py ") + sys.exit(1) + + # Get the input string from the command-line argument + input_string = sys.argv[1] + + # Call the split_and_flat function and print the result + result = split_and_flat(input_string) + print(result)