Unique Elements in a List
Paul Rubin
http
Mon May 9 21:23:16 EDT 2005
"superprad at gmail.com" <superprad at gmail.com> writes:
> Is there an easy way to grab the Unique elements from a list?
> For Example:
> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
Untested: here's an iterator that gives you the index and value,
without reordering. Uses dicts instead of sets for backwards compatibility.
def unique_elements(data):
seen = {}
for n,x in data:
if x not in seen:
seen[x] = 1
yield n,x
More information about the Python-list
mailing list