I am writing a simple program in Python that has to merge two list. I have taken the following pseudocode from An Introduction to Analysis of Algorithm.

Now I have written following Program in Python.
def merge_list(a,b):
a,b = sorted(a),sorted(b)
p1,p2,i = 0,0,0 #python indices start from 0
c = [0 for x in range(len(a)+len(b))]
while i<(len(a)+len(b)):
if a[p1] <= b[p2]:
c[i] = a[p1]
p1 = p1 + 1
else:
c[i] = b[p1]
p2 = p2 + 1
i += 1
return c
res = merge_list([1,3,5],[2,4,6])
Now I am getting Error with IndexError: list index out of range . Please correct me what I am doing wrong here?
n>m? This pseudocode doesn't include enough preconditions.