[Tutor] Lists+sorting

Alan Gauld alan.gauld at btinternet.com
Mon Jan 4 12:27:46 EST 2016


On 04/01/16 16:56, Pooja Bhalode wrote:
> Hi,
> I wanted to check if I can write the following program in this manner as
> well.
> 

Can you resend in plain text please?
Your post lost all its formatting so its hard to read
or comment on.

> def linear_merge(list1, list2):
> result = []
> while len(list1) and len(list2):
> if list1[0] < list2[0]:
> result.append(list1.pop(0))
> else:
> result.append(list2.pop(0))
> 
> # Now tack on what's left
> 
> result.extend(list1)
> result.extend(list2)
> return result

...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list