From 68a60ea8734e88088a41bdb7bfb40f4541d2f8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 22 Oct 2023 17:36:49 +0200 Subject: [PATCH] Improve name handling Considered reversed first and last name order for uniqueness Sort names with same words close to each other --- merge-csv-lists.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/merge-csv-lists.py b/merge-csv-lists.py index 74b3e22..c695552 100644 --- a/merge-csv-lists.py +++ b/merge-csv-lists.py @@ -30,8 +30,14 @@ def unique_combined_list(input1, input2): if name not in final_list: final_list.append(name) - # Sort the list - sorted_list = sorted(final_list) + # Flatten the list into individual words + flattened_words = [word for name in combined_list for word in name.split()] + + # Sort the list based on the criteria discussed above + sorted_list = sorted( + final_list, + key=lambda x: (flattened_words.index(x.split()[0]), combined_list.index(x)), + ) # Convert the list back to a comma-separated string output = ",".join(sorted_list)