merge-csv-lists: allow any number of arguments

This commit is contained in:
Lukáš Kucharczyk 2023-10-22 17:43:02 +02:00
parent 68a60ea873
commit 07430482d4
1 changed files with 12 additions and 11 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 = []
@ -48,18 +46,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)