Merging multiple sorted sequences.

Ian Kelly ian.g.kelly at gmail.com
Wed Apr 12 18:45:57 EDT 2017


On Wed, Apr 12, 2017 at 4:44 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Wed, Apr 12, 2017 at 4:15 PM, Erik <python at lucidity.plus.com> wrote:
>>     while len(items) > 1:
>>         items.sort(key=lambda item: item[0])
>
> This might be okay since Timsort on an already-sorted list should be
> O(n). But there's not really any need to keep them sorted and I would
> just use "lowest = min(items, key=itemgetter(0))".

Actually, you should consider using a heap.


More information about the Python-list mailing list