On Tue, 22 Mar 2005 13:15:15 -0500, Leeds, Mark wrote:
> I want to do a sort on a list of objects based on a similar attributes in
> each object for example time of creation of this object. 

    >>> 
    >>> class Student:
    ...         def __init__(self, name, age):
    ...                 self.name = name
    ...                 self.age = age
    ... 
    >>> 
    >>> students = [Student('John', 18), Student('Jill', 17)]
    >>> students.sort(lambda x,y: cmp(x.age, y.age))
    >>> [student.name for student in students]
    ['Jill', 'John']
    >>> 

See `help(list.sort)` for details.

-- 
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to