Compare commits

...

2 Commits

1 changed files with 14 additions and 19 deletions

View File

@ -2,13 +2,11 @@
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(",")]
def unique_combined_list(*inputs):
# Combine lists
combined_list = list1 + list2
combined_list = [
item.strip().title() for input_list in inputs for item in input_list.split(",")
]
# Create an empty list to store the final unique names
final_list = []
@ -30,14 +28,8 @@ def unique_combined_list(input1, input2):
if name not in final_list:
final_list.append(name)
# 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)),
)
# Sort the list
sorted_list = sorted(final_list)
# Convert the list back to a comma-separated string
output = ",".join(sorted_list)
@ -48,18 +40,21 @@ def unique_combined_list(input1, input2):
def main():
# Create an argument parser
parser = argparse.ArgumentParser(
description="Combine two comma-separated lists into one unique sorted list."
description="Combine multiple 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.")
# Add a variable number of input lists
parser.add_argument("lists", nargs="+", type=str, help="Comma-separated lists.")
# Parse the arguments
args = parser.parse_args()
# If only one list is provided, use it twice
if len(args.lists) == 1:
args.lists.append(args.lists[0])
# Get the unique combined list
result = unique_combined_list(args.list1, args.list2)
result = unique_combined_list(*args.lists)
print(result)