change sort(cmp=...) to sort(key=...) to be compatible with py3