Sorting a list of classes

Ray&Maria nospam at nowhere.net
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

Ray
NOSPAMjchen at NOSPAMquark.com


"Michael Hudson" <mwh21 at cam.ac.uk> wrote in message
news:m3snwafxek.fsf at atrus.jesus.cam.ac.uk...
> "lexberezhny" <lexberezhny at email.msn.com> 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, http://www.cs.yale.edu/~perlis-alan/quotes.html





More information about the Python-list mailing list