Monday, December 23, 2019

IslandT: Create a python function which will merge, sort and remove duplicate values from lists

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

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...