Compare commits
No commits in common. "f9faf4f8a4c5956732fb67844445b7be84af0130" and "68a60ea8734e88088a41bdb7bfb40f4541d2f8ed" have entirely different histories.
f9faf4f8a4
...
68a60ea873
|
@ -2,11 +2,13 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def unique_combined_list(*inputs):
|
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
|
# Combine lists
|
||||||
combined_list = [
|
combined_list = list1 + list2
|
||||||
item.strip().title() for input_list in inputs for item in input_list.split(",")
|
|
||||||
]
|
|
||||||
|
|
||||||
# Create an empty list to store the final unique names
|
# Create an empty list to store the final unique names
|
||||||
final_list = []
|
final_list = []
|
||||||
|
@ -28,8 +30,14 @@ def unique_combined_list(*inputs):
|
||||||
if name not in final_list:
|
if name not in final_list:
|
||||||
final_list.append(name)
|
final_list.append(name)
|
||||||
|
|
||||||
# Sort the list
|
# Flatten the list into individual words
|
||||||
sorted_list = sorted(final_list)
|
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
|
# Convert the list back to a comma-separated string
|
||||||
output = ",".join(sorted_list)
|
output = ",".join(sorted_list)
|
||||||
|
@ -40,21 +48,18 @@ def unique_combined_list(*inputs):
|
||||||
def main():
|
def main():
|
||||||
# Create an argument parser
|
# Create an argument parser
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Combine multiple comma-separated lists into one unique sorted list."
|
description="Combine two comma-separated lists into one unique sorted list."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add a variable number of input lists
|
# Add arguments for the two input lists
|
||||||
parser.add_argument("lists", nargs="+", type=str, help="Comma-separated 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
|
# Parse the arguments
|
||||||
args = parser.parse_args()
|
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
|
# Get the unique combined list
|
||||||
result = unique_combined_list(*args.lists)
|
result = unique_combined_list(args.list1, args.list2)
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue