Sorting a list of class instances

Grant Ito Grant_Ito at shaw.ca
Wed Dec 25 15:30:35 EST 2002


Many thanks, Gerson!

"Gerson Kurz" <gerson.kurz at t-online.de> wrote in message
news:3e09ef94.43823093 at news.t-online.de...
> On Wed, 25 Dec 2002 17:29:11 GMT, "Grant Ito" <Grant_Ito at shaw.ca>
> wrote:
>
> >class Deck(list):
> >    def __init__(self, numCards):
> >        self = []
> >        for i in range(numCards):
> >            self.append(Card(i))
>
> The stmt "self = []" is reassigning the variable "self". "self" is not
> a keyword like "this" in python, its just a convention.
>
> What you want to do is: initialize the list class (the
> "list.__init__(self)" in the example below) instead:
>
> class Deck(list):
>     def __init__(self, numCards):
>         list.__init__(self) # <-------- initialize list baseclass
>         for i in range(numCards):
>             self.append(Card(i))
>
>





More information about the Python-list mailing list