Created
October 23, 2013 01:15
-
-
Save maxwillzq/7110909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jan 02 11:03:42 2013 | |
@author: qzhang | |
""" | |
import functools | |
a = [ 1,50,2,4,16] | |
def MyCmp(x,y): | |
return cmp(y,x) | |
print sorted(a,cmp=cmp) | |
print sorted(a,cmp = MyCmp) | |
#make a key function using cmp_to_key() | |
get_key = functools.cmp_to_key(MyCmp) | |
for i in a: | |
print get_key(i).obj | |
#sort it by key, but not by cmp | |
print sorted(a,key=get_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment