From 019813cc30ce57412c1c8943e3beda4c198dd5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 22 Oct 2023 17:35:16 +0200 Subject: [PATCH] bullet_list_to_unique_list: add --- bullet_list_to_unique_list.py | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 bullet_list_to_unique_list.py diff --git a/bullet_list_to_unique_list.py b/bullet_list_to_unique_list.py new file mode 100644 index 0000000..ed0ed44 --- /dev/null +++ b/bullet_list_to_unique_list.py @@ -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()