Creating a sorted concatenated list from two unsorted lists in Python

Python Methods and Functions

Examples:

 Input: list1 = [25, 18, 9, 41, 26, 31] list2 = [25, 45, 3, 32, 15, 20] Output: [3, 9 , 15, 18, 20, 25, 25, 26, 31, 32, 41, 45] Input: list1 = ["suraj", "anand", "gaurav", "aman", "kishore"] list2 = [" rohan "," ram "," mohan "," priya "," komal "] Output: [' aman', 'anand',' gaurav', 'kishore',' komal', 'mohan',' priya', 'ram',' rohan', 'suraj'] 

The + operator in Python helps us to concatenate two lists, be it a list of strings or integers, or a mixture of both. Finally, we sort the list using the sort () function.

# Python program to combine and sort two lists

def Merge (list1, list2):

final_list = list1 + list2

final_list.sort ()

  return (final_list)

  
Driver code

list1 = [ 2 5 , 18 , 9 , 41 , 26 , 31 ]

list2 = [ 25 , 45 , 3 , 32 , 15 , 20 ]

print (Merge (list1, list2))

Output:

 [3, 9, 15, 18, 20, 25, 25, 26, 31, 32, 41, 45] 




Tutorials