Yet another unique() function...
Paul Rubin
http
Tue Feb 27 21:55:11 EST 2007
Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> def unique(seq, keepstr=True):
> t = type(seq)
> if t==str:
> t = (list, ''.join)[bool(keepstr)]
> seen = []
> return t(c for c in seq if (c not in seen, seen.append(c))[0])
Preferable:
def unique(seq, keepstr=True):
t = type(seq)
if t==str:
t = (list, ''.join)[bool(keepstr)]
seen = []
return t(c for c in seq if not (c in seen or seen.append(c)))
More information about the Python-list
mailing list