split_and_flat: add
This commit is contained in:
parent
7477c13c34
commit
52becb8909
|
@ -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 <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)
|
Loading…
Reference in New Issue