Yet another unique() function...
MonkeeSage
MonkeeSage at gmail.com
Tue Feb 27 22:14:08 EST 2007
On Feb 27, 9:03 pm, "MonkeeSage" <MonkeeS... at gmail.com> wrote:
> On Feb 27, 8:55 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>
>
>
> > Paul Rubin <http://phr...@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)))
>
> Wow, nice! Very cool. :)
>
> Regards,
> Jordan
I posted this (attributed to you of course) in the comments section
for the recipe.
More information about the Python-list
mailing list