Tim Peters on speed!

Don Tuttle tuttledon at hotmail.com
Sun Nov 11 19:09:57 CET 2001

Ok, now that I have your attention <wink>...

In studing Tim' recipe "Remove duplicates from a sequence"

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?

          t = list(s)
    except TypeError:
          del t  # move on to the next method
          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]


More information about the Python-list mailing list