[Tutor] Lists+sorting

Joel Goldstick joel.goldstick at gmail.com
Mon Jan 4 12:45:42 EST 2016


On Mon, Jan 4, 2016 at 12:27 PM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> 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
>
> Like Alan said, send in plain text.  Also, give a test case and your
results.  Your version uses the built in sort method.  The linear merge
doesn't use that, so the writer's are trying to teach you something about
sorting.

> ...
>
> --
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays


More information about the Tutor mailing list