[code.view]

[top] / python / PyMOTW / heapq / heapq_extremes.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """
     """
     
     __version__ = "$Id$"
     #end_pymotw_header
     
     import heapq
     from heapq_heapdata import data
     
     print 'all       :', data
     print '3 largest :', heapq.nlargest(3, data)
     print 'from sort :', list(reversed(sorted(data)[-3:]))
     print '3 smallest:', heapq.nsmallest(3, data)
     print 'from sort :', sorted(data)[:3]
     

[top] / python / PyMOTW / heapq / heapq_extremes.py

contact | logmethods.com