Re: Yet another unique() function...
- From: "MonkeeSage" <MonkeeSage@xxxxxxxxx>
- Date: 28 Feb 2007 13:10:24 -0800
On Feb 28, 2:18 pm, Paul Rubin <http://phr...@xxxxxxxxxxxxxx> 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.append(c)))
This definitely works. I tried to post a message about this a few
hours ago, but I guess it didn't go through. I've already updated the
recipe and comments.
I think these iterator approaches get more readable as one becomes
used to them.
I agree. I understood your code in a matter of seconds.
.
- Follow-Ups:
- Re: Yet another unique() function...
- From: MonkeeSage
- Re: Yet another unique() function...
- References:
- Yet another unique() function...
- From: MonkeeSage
- Re: Yet another unique() function...
- From: bearophileHUGS
- Re: Yet another unique() function...
- From: Paul Rubin
- Yet another unique() function...
- Prev by Date: Re: Question about raise and exceptions.
- Next by Date: Re: convert many excel files to pdf in batch
- Previous by thread: Re: Yet another unique() function...
- Next by thread: Re: Yet another unique() function...
- Index(es):
Relevant Pages
|