Jason Tackaberry wrote:
> On Thu, 2005-10-27 at 19:57 +0200, Dirk Meyer wrote:
>> +def smartsort(x,y):
>> +    """
>> +    Compares strings after stripping off 'The' and 'A' to be 'smarter'
>> +    Also obviously ignores the full path when looking for 'The' and 'A'
>> +    """
>> +    m = os.path.basename(x)
>> +    n = os.path.basename(y)
>> +
>> +    for word in ('The', 'A'):
>> +        word += ' '
>> +        if m.find(word) == 0:
>> +            m = m.replace(word, '', 1)
>> +        if n.find(word) == 0:
>> +            n = n.replace(word, '', 1)
>> +
>> +    return cmp(m.upper(),n.upper()) # be case insensitive
>
> I don't really audit your check-ins or anything, but I was skimming this
> one and this function caught my eye.

I only moved stuff around without reading it. Blame Aubin :)

>  I'd do it this way:
>
>         for word in ('The ', 'A '):  # Put the space in the literal
>            if m.startswith(word):    # use startswith(), faster
>               m = m[len(word):]      # use slice, faster
>            if n.startswith(word):
>               n = n[len(word):]
>         return cmp(m.lower(), n.lower())   # use lower(), faster

I'm not sure we need this function this way. I hope to have two
"names" of an item in the future, one display and one sort item. IIRC
this is already in the mediaitem code, so this function is useless. 


Dischi

-- 
On-line, adj.:
        The idea that a human being should always be accessible to a computer.

Attachment: pgpzAHLVdvUyA.pgp
Description: PGP signature

Reply via email to