A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/337029.html below:

Removing duplicates from a list

Removing duplicates from a list Removing duplicates from a listSteven Bethard steven.bethard at gmail.com
Sat Sep 17 01:55:48 EDT 2005
drochom wrote:
> i suppose this one is faster (but in most cases efficiency doesn't
> matter)
> 
>>>>def stable_unique(s):
> 
> 	e = {}
> 	ret = []
> 	for x in s:
> 		if not e.has_key(x):
> 			e[x] = 1
> 			ret.append(x)
> 	return ret

I'll repeat Peter Otten's link to Tim Peters's recipe here:
     http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560/
Read the comments at the end, they talk about order-preserving lists.

See Raymond Hettinger's response:

     def uniq(alist)    # Fastest order preserving
         set = {}
         return [set.setdefault(e,e) for e in alist if e not in set]

STeVe

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4