Optimizing list processing
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Dec 11 20:43:31 EST 2013
On Thu, 12 Dec 2013 00:59:42 +0000, MRAB wrote:
>> table = [(x, i) for i,x in enumerate(iterable)]
>> table.sort()
>
> This looks wrong to me:
>
>> for x, i in table:
>> table[i] = x
Yes, you're right, I over-simplified the example, and in doing so
introduced a bug. What I actually use is:
for i, x in enumerate(table):
table[i] = x[1]
modulo any further bugs introduced while copying and pasting :-)
--
Steven
More information about the Python-list
mailing list