Member Avatar for soUPERMan

hello, was wondering how to sort a list which has different data types according to the data type,
Example if a list containing 'person' objects.
a person object wil have a name, gender and age like so:

person1 = person(name, gender, age)

so if i have 5 objects in a list and i wanna sort them first by name, then later by age, how do i go about that?

Recommended Answers

All 2 Replies

See the Student class under "Key Functions" here http://wiki.python.org/moin/HowTo/Sorting if you are talking about a list of classes. Also, see the "The Old Way Using the cmp Parameter" on the same page.

Member Avatar for soUPERMan

Thanks all....used the cmp method :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.