39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
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 <input_string>")
|
|
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)
|