A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-October/083070.html below:

[Python-Dev] heapq, min and max

[Python-Dev] heapq, min and maxAntoine Pitrou solipsis at pitrou.net
Wed Oct 22 16:05:41 CEST 2008
Kristján Valur Jónsson <kristjan <at> ccpgames.com> writes:
> timeit.Timer("(l.sort(), l[-1])",
> s).timeit(1000)
> 
> 0.29406761513791935

This is clearly wrong. l.sort() will sort the list in place when it is first
invoked, and therefore will be very fast in subsequent calls.

Compare with:

    timeit.Timer("sorted(l)[-1]", s).timeit(1000)

which really does what you are looking for (sorting then taking the max *on
every iteration*), and is much slower.

As for heapq, its critical parts are already implemented in C as of Python 2.5.2:

>>> import heapq, _heapq
>>> _heapq
<module '_heapq' from '/usr/lib/python2.5/lib-dynload/_heapq.so'>
>>> heapq.heapify is _heapq.heapify
True



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4