bullet_list_to_unique_list: add

This commit is contained in:
Lukáš Kucharczyk 2023-10-22 17:35:16 +02:00
parent 52becb8909
commit 019813cc30
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
#!/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()