Advertisement
rfmonk

bisect_example2.py

Jan 13th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import bisect
  5. import random
  6.  
  7. # Reset the seed
  8. random.seed(1)
  9.  
  10. print 'New Pos Contents'
  11. print '--- --- --------'
  12.  
  13. # Use bisect_left and insort_left.
  14. l = []
  15. for i in range(1, 15):
  16.     r = random.randint(1, 100)
  17.     position = bisect.bisect_left(l, r)
  18.     bisect.insort_left(l, r)
  19.     print '%3d %3d' % (r, position), 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement