Need Help sorting alphabetically.

eff at eff at
Wed Dec 20 12:09:27 CET 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


Sent via

More information about the Python-list mailing list