Intermediate · Lists · 125 of 264
Merge two sorted lists
Merge two lists that are each sorted into one sorted list, walking through both at once (do not just call sorted()).
Input: two lines of sorted whole numbers. Output: all the numbers in sorted order.
Examples
Input
1 4 9 2 3 10
Output
1 2 3 4 9 10
Input
1 2 3 4 5 6
Output
1 2 3 4 5 6
Input
5 1 5 5
Output
1 5 5 5
One more test checks other inputs when you press Check.
Stuck? The idea behind lists
A list keeps several values in order: [3, 9, 1]. Its items are numbered from 0, like a string's characters.
append() adds to the end; sum(), min(), max(), len() and sorted() work on a whole list. Read numbers from one line with input().split() and int().
numbers = [int(x) for x in input().split()] print(sum(numbers), max(numbers)) numbers.append(0) print(numbers)
Watch for: split() gives text: "10" sorts before "9". Turn each item into a number before comparing or adding.