Finding the insertion point in a list

7stud bbxx789_05ss at yahoo.com
Fri Mar 16 16:10:10 EDT 2007


How about:

-----------
x = [0, 100, 200, 1000]
y = -1
inserted = False

for i in range(len(x)):
        if(y <= x[i]):
                x.insert(i, y)
                inserted = True
                break
if(not inserted): x.append(y)

print x
------------




More information about the Python-list mailing list