Keeping track of the N largest values

n00m n00m at narod.ru
Sun Dec 26 08:56:14 EST 2010


from bisect import insort_left

K = 5
top = []
while 1:
    x = input()
    if len(top) < K:
        insort_left(top, x)
    elif x > top[0]:
        del top[0]
        insort_left(top, x)
    print top


will be enough




More information about the Python-list mailing list