R: unique items in lists
comp.lang.python
micampe at f2s.com
Tue Mar 27 05:39:21 EST 2001
Here is what I'm doing now:
for w in words:
while words.count(w) > 1:
words.remove(w)
comments?
Remco Gerlich <scarblac at pino.selwerd.nl> wrote in message
slrn9c0ph1.o5h.scarblac at pino.selwerd.nl...
> comp.lang.python <micampe at f2s.com> wrote in comp.lang.python:
> > Which is the best (read: fastest) way to remove duplicated items from a
list
> > of strings?
>
> The standard idiom is to put the items in a dictionary, then get the
> dictionary keys:
>
> def unique_strings(l):
> dict = {}
> for s in l:
> dict[s] = 1
> return dict.keys()
>
> I think this is also very fast, at least lots faster than comparing all
the
> strings in a double for loop or something.
>
> --
> Remco Gerlich
More information about the Python-list
mailing list