[Tutor] Sorting Instance Attributes

Alan Colburn aicolburn@yahoo.com
Wed Dec 11 18:55:01 2002


Hi all--

I wrote a program awhile ago to help me keep track of
attendance in my courses. Now, as an exercise, I've
decided to rewrite the program OOP-style. Among other
things, each student will be an object. The Student
class constructor begins with this code:

class Student:
     def __init__(self, firstName, lastName):
          self.firstName=firstName
          self.lastName=lastName

Adding a student into the course amounts to creating a
new instance of the Student class. Now, onto my
questions:

1. If I'd like to record most student information
within individual Student class instances, what would
be the recommended type (is that the right word?) to
use for storing the collection of Student objects?
List? Dictionary? I'll save the information via
cpickle or shelve.

2. [Here's the one that I'm stumped on...] How do I
sort objects via a single object attribute. In the
example above, suppose I'd like to create a class
list, sorted alphabetically via lastName? 

As always, thanks for your help! -- Al Colburn

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com