How does sorting work? I saw this function but i have no idea how it works.
python: items.sort( lambda a,b:cmp(a.Title(), b.Title()) )
Thanks for any help.
sort can take in a comparison function.
The comparison function takes in 2 arguments and returns them in sorted form.
Eg. this will return a negative number to indicate it is to be reversed to sort it
So to sort the array called 'items', you would use
The only diff in ur code is that they used a 'lambda function' which is a function but without a name.) My compare function has the name 'compare' associated to the funtion object.
I pass the function into the sort function as an argument. In their code, they create an anonymous function there and then to pass in as an argument. So their code could be re-written as:
Last edited by lazy_yogi; May 30th, 2003 at 11:21 AM.
Thanks for you help, I appreciate it.