This is a follow up question
To the previous question
About sorting that
I sent for my friend.
-----Original Message-----
From: Tan, Heap Ho
Sent: Tuesday, March 22, 2005 2:06 PM
To: Leeds, Mark
Subject: RE: FW: Python help group
How can you speed it? Does anyone know if pytable can take
non-homogeneous objects type?
-----Original Message-----
From: Leeds, Mark
Sent: Tuesday, March 22, 2005 1:39 PM
To: Tan, Heap Ho
Subject: FW: FW: Python help group
-----Original Message-----
From: Swaroop C H [mailto:swaroopc h@gmail.com]
Sent: Tuesday, March 22, 2005 1:25 PM
To: Leeds, Mark
Cc: python-list@python.org
Subject: Re: FW: Python help group
On Tue, 22 Mar 2005 13:15:15 -0500, Leeds, Mark wrote:[color=blue]
> I want to do a sort on a list of objects based on a similar attributes[/color]
in[color=blue]
> each object for example time of creation of this object. [/color]
[color=blue][color=green][color=darkred]
>>>
>>> class Student:[/color][/color][/color]
... def __init__(self, name, age):
... self.name = name
... self.age = age
... [color=blue][color=green][color=darkred]
>>>
>>> students = [Student('John', 18), Student('Jill', 17)]
>>> students.sort(l ambda x,y: cmp(x.age, y.age))
>>> [student.name for student in students][/color][/color][/color]
['Jill', 'John'][color=blue][color=green][color=darkred]
>>> [/color][/color][/color]
See `help(list.sort )` for details.
--
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
To the previous question
About sorting that
I sent for my friend.
-----Original Message-----
From: Tan, Heap Ho
Sent: Tuesday, March 22, 2005 2:06 PM
To: Leeds, Mark
Subject: RE: FW: Python help group
How can you speed it? Does anyone know if pytable can take
non-homogeneous objects type?
-----Original Message-----
From: Leeds, Mark
Sent: Tuesday, March 22, 2005 1:39 PM
To: Tan, Heap Ho
Subject: FW: FW: Python help group
-----Original Message-----
From: Swaroop C H [mailto:swaroopc h@gmail.com]
Sent: Tuesday, March 22, 2005 1:25 PM
To: Leeds, Mark
Cc: python-list@python.org
Subject: Re: FW: Python help group
On Tue, 22 Mar 2005 13:15:15 -0500, Leeds, Mark wrote:[color=blue]
> I want to do a sort on a list of objects based on a similar attributes[/color]
in[color=blue]
> each object for example time of creation of this object. [/color]
[color=blue][color=green][color=darkred]
>>>
>>> class Student:[/color][/color][/color]
... def __init__(self, name, age):
... self.name = name
... self.age = age
... [color=blue][color=green][color=darkred]
>>>
>>> students = [Student('John', 18), Student('Jill', 17)]
>>> students.sort(l ambda x,y: cmp(x.age, y.age))
>>> [student.name for student in students][/color][/color][/color]
['Jill', 'John'][color=blue][color=green][color=darkred]
>>> [/color][/color][/color]
See `help(list.sort )` for details.
--
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info