Need Help sorting alphabetically.

eff at my-deja.com eff at my-deja.com
Wed Dec 20 06:09:27 EST 2000


Greg Jorgensen wrote:
> > It seems you want to ignore case and ignore everything outside a-z.
> > So make a function that throws out all of the other characters and
> > turns the rest into a single case, and then compares those:
> >
> > def compare_alphabetically(a, b):
> >    a = filter(lambda x: x.isalpha(), a.upper())
> >    b = filter(lambda x: x.isalpha(), b.upper())
> >    return cmp(a,b)
>
> The filter is unnecessary; the upper() and lower() methods of
> string only change alphabetic characters.

...but they don't "throw out all other characters".  the original
code matches his description, your proposed replacement doesn't.

(note that it's probably more efficient to use the translate
function/method instead of the filter trick, but that's another
story).

</F>


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list