List without duplicates?

Aahz Maruch aahz at netcom.com
Tue Jun 20 19:28:36 EDT 2000


In article <394FFA1A.FBF8F81D at roguewave.com>,
Bjorn Pettersen  <bjorn at roguewave.com> wrote:
>
>This should probably be a faq by now...:

Yup.

>def unique(lst):
>    d = {}
>    for item in lst:
>        d[item] = None
>    return d.keys()

The Timbot recommends

        d[item] = 1

because there's no lookup involved on 1, so it's fractionally faster.
(Any other constant should probably work the same.)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"This is Usenet.  We're all masturbating in public places."  -DH



More information about the Python-list mailing list