Amdocs Coding Question | Merge and Sort List in Python

Hello friends, I hope you all are doing great. In this post today we will learn to solve the  coding questions which is being asked by the Amdocs company recently. If you are preparing for selection in any company then this post will help you definitely.

Lets Start

Merge and Sort List in Python

In this task you are requested to merge two lists into a sorted list (sorting should be in ascending order) . The function should also remove any duplicated numbers.

For example: given the following lists 

list1 = [-1, 1, 3, 5, 7, 9]

list2 = [-2, 2, 3, 4, 5, 6]


The function should return:

[-2, -1, 1, 2, 3, 4, 5, 6, 7, 9]

Example :-

  • Input:
    •  [-1, 1, 3, 5, 7, 9]
    • [-2, 2, 3, 4, 5, 6]
  • Output:
    • [-2, -1, 1, 2, 3, 4, 5, 6, 7, 9]

Code in Python

# code in Python
def SortedList(list1, list2):
    for i in list2:
        if i not in list1:
            list1.append(i)
    list1.sort()
    return list1
# Driver code
l1 = [-1, 1, 3, 5, 7, 9];
l2 = [-2, 2, 3, 4, 5, 6]
print(SortedList(l1, l2))

# Output
[-2, -1, 1, 2, 3, 4, 5, 6, 7, 9]

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks

Post a Comment

0 Comments