From 7477c13c3445ca1a8c2866e4e3007b11d77cabb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 22 Oct 2023 17:34:48 +0200 Subject: [PATCH] merge-csv-lists: add --- merge-csv-lists.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 merge-csv-lists.py diff --git a/merge-csv-lists.py b/merge-csv-lists.py new file mode 100644 index 0000000..74b3e22 --- /dev/null +++ b/merge-csv-lists.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +import argparse + + +def unique_combined_list(input1, input2): + # Split each input by comma and trim whitespace + list1 = [item.strip().title() for item in input1.split(",")] + list2 = [item.strip().title() for item in input2.split(",")] + + # Combine lists + combined_list = list1 + list2 + + # Create an empty list to store the final unique names + final_list = [] + + # Check for reversed names + for name in combined_list: + parts = name.split() + + # If the name has two words, check for its reversed variant + if len(parts) == 2: + first, last = parts + reversed_name = f"{last} {first}" + + # If neither the name nor its reversed variant is in the final list, add the name + if name not in final_list and reversed_name not in final_list: + final_list.append(name) + # If it's a single-word name, simply add it if it's not in the final list + else: + if name not in final_list: + final_list.append(name) + + # Sort the list + sorted_list = sorted(final_list) + + # Convert the list back to a comma-separated string + output = ",".join(sorted_list) + + return output + + +def main(): + # Create an argument parser + parser = argparse.ArgumentParser( + description="Combine two comma-separated lists into one unique sorted list." + ) + + # Add arguments for the two input lists + parser.add_argument("list1", type=str, help="The first comma-separated list.") + parser.add_argument("list2", type=str, help="The second comma-separated list.") + + # Parse the arguments + args = parser.parse_args() + + # Get the unique combined list + result = unique_combined_list(args.list1, args.list2) + + print(result) + + +if __name__ == "__main__": + main()