Menu Close

Python Program to Merge Two Lists and Sort it.

Python Program to Merge Two Lists and Sort it.

Input:
Number of elements in the list 1
Elements of the List 1
Number of Elements in in the List 2
Element of List 2

Output:
Print the sorted List

#Here the N value has no use, its here for the question only.
#check out the Input 3 and 4 having get input without N values.

#N1=int(input('Enter N value for list1 : '))
l1=list(map(int,input('Enter the values for list1 : ').split(' ')))
#N2=int(input('Enter N value for list2 : '))
l2=list(map(int,input('Enter the values for list2 : ').split(' ')))

print('Sorted list is:',(*sorted(l1+l2)))

Input_1:
Enter N value for list1 : 2
Enter the values for list1 : 67 43
Enter N value for list2 : 2
Enter the values for list2 : 22 11
Output:
Sorted list is: 11 22 43 67


Input_2:
Enter N value for list1 : 3
Enter the values for list1 : 28 65 56
Enter N value for list2 : 2
Enter the values for list2 : 43 29
Output:
Sorted list is: 28 29 43 56 65


Input_3:
Enter the values for list1 : 69 5 22 3658 45
Enter the values for list2 : 6 55 846 325 75 96 100
Output:
Sorted list is: 5 6 22 45 55 69 75 96 100 325 846 3658


Input_4:
Enter the values for list1 : 9 6 3 4 8 5 7 2
Enter the values for list2 : 5 3 2 8 7 4 9 6 5
Output:
Sorted list is: 2 2 3 3 4 4 5 5 5 6 6 7 7 8 8 9 9


Morae Q!