[Greg Ewing] > > The only issue then is to avoid comparing the whole > > record, and this presumably should be non-optional > > as well. [Guido] > Right. I think we've settled on using small wrapper objects instead > of tuples, whose comparison *only* compares the key value, and whose > other field contains a reference to the full record. When passing > both cmp and key, cmp is passed the key field from the wrapper. Here is an implementation to try out. This second patch includes unittests and docs. The reference counts work out file for repeated test runs and the rest of the test suite passes just fine: www.python.org/sf/823292 * The optional keywords arguments are: cmp, key, reverse. * The key function triggers a DSU step with a wrapper object that holds the full record but returns only the key for a comparison. This is fast, memory efficient, and doesn't change the underlying stability characteristics of the sort. (I think this was Neil's idea -- and it works like a charm.) * If the key function is not specified, no wrapping occurs so that sort performance is not affected. Raymond Hettinger ################################################################# ################################################################# ################################################################# ##### ##### ##### ################################################################# ################################################################# #################################################################
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