Python functools.cmp to key

flashcards

Python 将 compare 函数转换为 key
?
functools.cmp_to_key(compare_function)
compare_function(x, y) 返回:

  1. -1 if x < y
  2. 0 if x == y
  3. 1 if x > y

Last update : May 23, 2023
Created : May 23, 2023