Problem with the sort() function
John Machin
sjmachin at lexicon.net
Tue Feb 22 16:21:59 EST 2005
clementine wrote:
> Thanx Nick...I forgot to mention im using python 2.2 and along with a
host
> of other things it doesnt seem to have the enumarate built in
function
> :(:(:(...is it possible to replace it by something else? I dont think
> simulating it will be feasible....
Faced with Nick's one line of code that uses 'enumerate', you have the
choice of building (and testing) an elaborate time machine to make a
SLOW 'enumerate' available for 2.2, or you can just patch Nick's
sorting gadget in a very straightforward manner:
modern as per Nick:
seq = [(key(elem), i, elem) for i, elem in enumerate(seq)]
ancient:
seq = [(key(seq[i]), i, seq[i]) for i in xrange(len(seq))]
More information about the Python-list
mailing list