[docs] insort-insert

Sandro Tosi sandro.tosi at gmail.com
Wed Feb 16 23:49:26 CET 2011


Hi Erden,
thanks for your email

On Wed, Feb 9, 2011 at 22:02, Erden Oktay <oktay_erden at wheatonma.edu> wrote:
>> import bisect
>>>>
>>>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')]
>>>> bisect.insort(scores, (300, 'ruby'))
>>>> scores
>
> [(100, 'perl'), (200, 'tcl'), (300, 'ruby'), (400, 'lua'), (500, 'python')]
>
> I thought instead of insort you meant insert.

I see why you think it's a typo, but bisect module has a 'insort()'
method for real :) it inserts an element in an already sorted
sequence, keeping it sorted. you can refer for a more detailed
description to the online doc[1].

[1] http://docs.python.org/library/bisect.html#bisect.insort

Cheers,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi


More information about the docs mailing list