[Python-Dev] decorate-sort-undecorate
Phillip J. Eby
pje at telecommunity.com
Mon Oct 13 21:53:33 EDT 2003
More information about the Python-Dev mailing list
Mon Oct 13 21:53:33 EDT 2003
- Previous message: [Python-Dev] Re: python-dev Summary for 2003-09-16 through 2003-09-30
- Next message: [Python-Dev] decorate-sort-undecorate
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 07:45 PM 10/13/03 -0400, Tim Peters wrote: >[Phillip J. Eby] > > Why not just have the decoration be (key,index,value) then? Why does > > the key function need the index? > >It doesn't if indices are synthesized by magic under the covers. It's not magic if that's the defined behavior, e.g.: """Specifying a 'key' callable causes items' sort order to be determined by comparing 'key(item)' in place of the item being compared. In the event that 'key()' returns an equal value for two different items, the items' order in the original list is preserved. The 'key' callable is called only once for each item in the list, so in general sorting with 'key' is faster than sorting with 'cmpfunc'. It requires more memory, however, because it creates a temporary list of '(key(item),original_item_position,item)' tuples in order to perform the sort.""" >If you want to pay that expense now, you do so >explicitly, and nothing about it is hidden. What expense? The extra memory overhead for the index? I suppose so. But if you *don't* want that behavior, you can still DSU manually, no?
- Previous message: [Python-Dev] Re: python-dev Summary for 2003-09-16 through 2003-09-30
- Next message: [Python-Dev] decorate-sort-undecorate
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list