Can I sort out a list by highest or lowest value in object properties?

If so how?? I want the AI to pursue whoever has the highest value in a certain property or random from a certain range. Where can I find info on learning that?

Thanks,

Chee, asked and answered again:


list = [x,y,z]
for ob in list:
    if 'property' in ob:
        highestProperty = sorted(list, key=lambda sortkey: sortkey['property'], reverse=True )

#Then highestProperty[0] becomes the highest


I don’t know how to add tabs in the code?

http://www.elysiun.com/forum/showthread.php?241776-List-sorting-syntax
https://wiki.python.org/moin/HowTo/Sorting/

(4 spaces = a tab)

Or you copy&paste it from an text editor.

Instead of using the lambda function, you can use itemgetter from the operator module

Thanks, everyone.