blob: 450ed6aa894a852577dc65af11128a46ae643582 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
""" Helper functions used in tatt"""
## Getting unique elements of a list ##
def unique(seq, idfun=None):
"""Returns the unique elements in a list
order preserving"""
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
# in old Python versions:
# if seen.has_key(marker)
# but in new ones:
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result
|