Posted by: Sourav | December 12, 2016

Combine two already sorted lists and sort the result and add it to a list in Python


M=[35,47,53,100]
N=[43,63,78,200]
o=[]

i=0
j=0
signal=0
while (len(M)>0 ):

j=0
while (j<len(N) ):

##        print str(M[i]) +” and “+str(N[j])
if M[i]>=N[j]:
o.append(N.pop(j))

else:
j=j+1
print “j”+str(j)

o.append(M.pop(0))

if len(N)==0 or len(M)==0 :
break
print o

##
if (len(M)==0) and (len(N)!=0):

#print “matched”
for i in range(0,(len(N))):

o.append(N.pop(0))

if (len(M)!=0) and (len(N)==0):
#print “matched”
for i in range(0,len(M)):
o.append(M.pop(0))
print o

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: