merge two list

# Taking user input as space-separated values
list1_input = input("Enter list 1 (space-separated): ").split()
list2_input = input("Enter list 2 (space-separated): ").split()

# Convert input strings to integers using a loop
list1 = []
for num in list1_input:
list1.append(int(num))

list2 = []
for num in list2_input:
list2.append(int(num))

# Sort both lists
list1.sort()
list2.sort()

# Merge sorted lists using sorted()
merged_list = (list1 + list2)
merged_list.sort()

# Print the merged sorted list
print("Merged Sorted List:", merged_list)


Leave a Reply

Your email address will not be published. Required fields are marked *