merge-csv-lists: allow any number of arguments
This commit is contained in:
parent
68a60ea873
commit
07430482d4
|
@ -2,13 +2,11 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def unique_combined_list(input1, input2):
|
def unique_combined_list(*inputs):
|
||||||
# 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 = 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
|
# Create an empty list to store the final unique names
|
||||||
final_list = []
|
final_list = []
|
||||||
|
@ -48,18 +46,21 @@ def unique_combined_list(input1, input2):
|
||||||
def main():
|
def main():
|
||||||
# Create an argument parser
|
# Create an argument parser
|
||||||
parser = argparse.ArgumentParser(
|
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
|
# Add a variable number of input lists
|
||||||
parser.add_argument("list1", type=str, help="The first comma-separated list.")
|
parser.add_argument("lists", nargs="+", type=str, help="Comma-separated lists.")
|
||||||
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.list1, args.list2)
|
result = unique_combined_list(*args.lists)
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue