In this example, we will create a single python function that will accept unlimited lists of numbers and merges them into a single list that contains sorted values as well as no duplicated values. This question is from Codewars which I have further modified it to accept unlimited lists instead of two.
def merge_arrays(*kwargs): merge_list = [] for li in kwargs: merge_list += li merge_list = list(dict.fromkeys(merge_list)) merge_list.sort() return merge_list
Run the above code with the below line of statement and see the outcome by yourself.
print(merge_arrays([1,2,3,5,6,1], [1,3,5], [9,0]))
If you have a better idea, don’t forget to leave them under the comment box below!
from Planet Python
via read more
No comments:
Post a Comment