Tim Peters on speed!
Don Tuttle
tuttledon at hotmail.com
Sun Nov 11 13:09:57 EST 2001
Ok, now that I have your attention <wink>...
In studing Tim' recipe "Remove duplicates from a sequence"
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
Tim assigns the result back to the original list rather than a new list.
Was this done for performance or convenients? Is there a performance
penalty for using a second list?
try:
t = list(s)
t.sort()
except TypeError:
del t # move on to the next method
else:
assert n > 0
last = t[0]
lasti = i = 1
while i < n:
if t[i] != last:
t[lasti] = last = t[i]
lasti += 1
i += 1
return t[:lasti]
Don
More information about the Python-list
mailing list