Re: Yet another unique() function...

2007-03-01 Thread MonkeeSage
On Feb 28, 3:46 pm, Paul Rubin wrote: > I didn't think so but I can't conveniently test it for now. Maybe > tonight. After playing with it a bit (only have 2.5 on this box), it looks like you do need to subscript the next() call. For example, the return from "unique( [[

Re: Yet another unique() function...

2007-02-28 Thread Paul Rubin
"MonkeeSage" <[EMAIL PROTECTED]> writes: > In your case optimized version, in the second try clause using > itertools, it should be like this, shouldn't it? > > return t(g.next()[1] for k,g in groupby(s, lambda (i,v): v)) I didn't think so but I can't conveniently test it for now. Maybe tonight.

Re: Yet another unique() function...

2007-02-28 Thread MonkeeSage
Paul, In your case optimized version, in the second try clause using itertools, it should be like this, shouldn't it? return t(g.next()[1] for k,g in groupby(s, lambda (i,v): v)) ^^^ Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another unique() function...

2007-02-28 Thread MonkeeSage
On Feb 28, 2:18 pm, Paul Rubin wrote: > Unicode fix (untested): > > def unique(seq, keepstr=True): > t = type(seq) > if t in (unicode, str): > t = (list, t('').join)[bool(keepstr)] > seen = [] > return t(c for c in seq if not (c in seen or seen.app

Re: Yet another unique() function...

2007-02-28 Thread Paul Rubin
[EMAIL PROTECTED] writes: > It's more terse, but my version is built to be faster in the more > common cases of all hashable or/and all sortable items (while working > in other cases too). > Try your unique on an unicode string, that's probably a bug (keepstr > is being ignored). > Version by Paul

Re: Yet another unique() function...

2007-02-27 Thread bearophileHUGS
MonkeeSage: > Here's yet another take on a unique() function for sequences. It's > more terse than others I've seen and works for all the common use > cases (please report any errors on the recipe page): It's more terse, but my version is built to be faster in the more common cases of all hashable

Re: Yet another unique() function...

2007-02-27 Thread Paul Rubin
"Paul McGuire" <[EMAIL PROTECTED]> writes: > Any reason not to use a set for the 'seen' variable? Yes, the sequence can contain non-hashable elements. See the test vectors for examples. -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another unique() function...

2007-02-27 Thread Paul McGuire
On Feb 27, 8:55 pm, Paul Rubin wrote: > Paul Rubin 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

Re: Yet another unique() function...

2007-02-27 Thread MonkeeSage
On Feb 27, 9:03 pm, "MonkeeSage" <[EMAIL PROTECTED]> wrote: > On Feb 27, 8:55 pm, Paul Rubin wrote: > > > > > Paul Rubin writes: > > > def unique(seq, keepstr=True): > > > t = type(seq) > > > if t==str: > > > t = (list, ''.join)[

Re: Yet another unique() function...

2007-02-27 Thread MonkeeSage
On Feb 27, 8:55 pm, Paul Rubin wrote: > Paul Rubin 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

Re: Yet another unique() function...

2007-02-27 Thread Paul Rubin
Paul Rubin 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 =

Re: Yet another unique() function...

2007-02-27 Thread Paul Rubin
"MonkeeSage" <[EMAIL PROTECTED]> writes: > Here's yet another take on a unique() function for sequences. It's > more terse than others I've seen and works for all the common use > cases (please report any errors on the recipe page): > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/50226

Yet another unique() function...

2007-02-27 Thread MonkeeSage
Here's yet another take on a unique() function for sequences. It's more terse than others I've seen and works for all the common use cases (please report any errors on the recipe page): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502263 Regards, Jordan -- http://mail.python.org/mail