sorted_copy.py

Go to the documentation of this file.
00001 def sorted_copy(alist, _indices=xrange(sys.maxint)):
00002     # the 'decorate' step: make a list such that each item
00003     # is the concatenation of sort-keys in order of decreasing
00004     # significance -- we'll sort this auxiliary-list
00005     decorated = zip(alist, _indices)
00006 
00007     # the 'sort' step: just builtin-sort the auxiliary list
00008     decorated.sort()
00009 
00010     # the 'undecorate' step: extract the items from the
00011     # decorated, and now correctly sorted, auxiliary list
00012     return [ item for item, index in decorated ]
00013 
00014 def sort_inplace(alist):
00015     # if "inplace" sorting is desired, simplest is to assign
00016     # to a slice-of-all-items of the original input list
00017     alist[:] = sorted_copy(alist)
00018 
00019 
00020 
00021 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...