Q:

Merging Lists python

Let’s Get Together – Merging Lists
Let a and b be sorted (smallest to largest) lists of integers of possibly different lengths.
Write a program that “merges” a and b to create list c. List c must be comprised of all the elements of a and b, and must also be in sorted (smallest to larges) order.
Note: Your program may not use the list method sort() on list c, or sort the values in list c in any way.
What I wrote:
from random import randint
a=[randint(1,200) for i in range(20)]
a.sort()
b=[randint(1,100) for j in range(15)]
b.sort()
c=a.extend(b)
print(c)

A:

If you know that both a and b are sorted, then you can look at the head of each list, compare the values, and then you can pick which one of those values is the smallest.  You can create list c by building it one element at a time, each time using the smallest integer available, until one list runs out.  Then just append the rest of the other list and you are done.

