Function to merge sorted lists

Matthew D. Wood woodm at equire.com
Thu Sep 6 15:02:30 EDT 2001


Would it be faster to use the list.pop command?  I doubt it, but then 
again, I'm always surprised.

John Goerzen wrote:

> "Edward C. Jones" <edcjones at erols.com> writes:
> 
>> Here is a Python program that does the same thing:
> 
> 
> There's a more straightforward way to do it:
> 
> def merge(l1, l2):
>     ret = []
>     l2c = 0
>     for item in l1:
>         while l2c < len(l2) and l2[l2c] < item:
>             ret.append(l2[l2c])
>             l2c += 1
>         ret.append(item)
>     return ret + l2[l2c:]
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20010906/509ee8e0/attachment.html>


More information about the Python-list mailing list