scripts/bullet_list_to_unique_list.py

40 lines
1000 B
Python

#!/usr/bin/python
import sys
import io
def extract_unique_values(input_string):
# Split the input string by newline to get the list of entries
input_list = input_string.strip().split("\n")
# Extract values from each entry in the format $VALUE1 - $VALUE2
values = [item.strip() for entry in input_list for item in entry.split("-")]
# Remove duplicates by converting to a set and back to a list
unique_values = list(set(values))
# Sort the list
sorted_values = sorted(unique_values)
# Convert the list back to a comma-separated string
output = ",".join(sorted_values)
return output
def main():
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8")
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
# Read the input from standard input
input_string = sys.stdin.read()
# Extract unique values
result = extract_unique_values(input_string)
print(result)
if __name__ == "__main__":
main()