Hi RC, 

>I have a list (x_list) of class data.

So, a list of instances/classes then.

You'll have to pass a custom function.

def tSort(objA,objB):
    #assuming that objA.x & objB.x are the items to sort by, and are
integers
    if objA < objB:
        result = -1
    elif objA = objB:
        result = 0
    elif objA > objB:
        #Would normally just do as an else
        #But being ultra explicit
        result = 1

    return result
 
x_list.sort(cmp=tSort)

Regards, 

Liam Clarke

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of CPIM Ronin
Sent: Tuesday, 8 November 2005 8:11 a.m.
To: [email protected]
Subject: [Tutor] simple report writing?


I have a list (x_list) of class data. How do I sort that list by a selected 
variable common to all members of the list?

x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see the 
individual items.

RC

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to