Advertisement
rfmonk

heapq_extremes.py

Jan 13th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import heapq
  5. from heapq_heapdata import data
  6.  
  7. print 'all      :', data
  8. print '3 largest:', heapq.nlargest(3, data)
  9. print 'from sort:', list(reversed(sorted(data)[-3:]))
  10. print '3 smallest:', heapq.nsmallest(3, data)
  11. print 'from sort:', sorted(data)[:3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement