Sorting a list of classes

Ray&Maria nospam at
Wed Apr 26 00:56:36 EDT 2000

No, you can sort classes, too.  It is very useful if you want to sort a list
of plug-ins in a pull-down menu.

class A:
    className = "A"
class B:
    className = "B"
class C:
    className = "C"

classList = [B, C, A]
print "before sorting:", classList
classList.sort(lambda a, b: cmp(a.className, b.className))
print "after sorting:", classList

NOSPAMjchen at

"Michael Hudson" <mwh21 at> wrote in message
news:m3snwafxek.fsf at
> "lexberezhny" <lexberezhny at> writes:
> > If i have a python list of classes, can i do something like
> > classList.sort() and how can i control this behavior within the
> > classes.
> Do you mean "class"?  In which case, no.  If you mean "instance", then
> see the other replies...
> Cheers,
> M.
> --
> 41. Some programming languages manage to absorb change, but
>     withstand progress.
>      -- Alan Perlis,

More information about the Python-list mailing list