libb.cmp

cmp(left, right)[source]

Python 2 style cmp function with null value handling.

Handles null values gracefully in sort comparisons.

Parameters:
  • left – First value to compare.

  • right – Second value to compare.

Returns:

-1 if left < right, 0 if equal, 1 if left > right.

Return type:

int

Example:

>>> cmp(None, 2)
-1
>>> cmp(2, None)
1
>>> cmp(-1, 2)
-1
>>> cmp(2, -1)
1
>>> cmp(1, 1)
0