ScaleRange

class whalrus.ScaleRange(low: int, high: int)[source]

A scale of consecutive integers.

Remark: for a scale of non-consecutive integers, such as {-1, 0, 2}, use the ScaleFromSet.

Parameters
  • low (int) – Lowest integer.

  • high (int) – Highest integer.

Examples

>>> scale = ScaleRange(low=0, high=5)
argsort(some_list: list, reverse: bool = False) → list[source]

Examples

>>> ScaleRange(low=0, high=5).argsort([3, 1, 4])
[1, 0, 2]
compare(one: object, another: object) → int

Compare two levels.

Parameters
  • one (object) – A level.

  • another (object) – A level.

Returns

0 if they are equal, a positive number if one is greater than another, a negative number otherwise.

Return type

int

Examples

>>> Scale().compare('a', 'z')
-1
eq(one: object, another: object) → bool

Test “equal”. Cf. lt().

ge(one: object, another: object) → bool

Test “greater or equal”. Cf. lt().

gt(one: object, another: object) → bool

Test “greater than”. Cf. lt().

property high

Examples

>>> ScaleRange(low=0, high=5).high
5
le(one: object, another: object) → bool

Test “lower or equal”. Cf. lt().

property low

Examples

>>> ScaleRange(low=0, high=5).low
0
lt(one: object, another: object) → bool

Test “lower than”.

Generally, only this method is overridden in the subclasses.

Parameters
  • one (object) – A level of the scale.

  • another (object) – A level of the scale.

Returns

True iff one is lower than another.

Return type

bool

Examples

>>> Scale().lt('a', 'z')
True
max(iterable: Iterable) → object[source]

Examples

>>> ScaleRange(low=0, high=5).max([3, 1, 4])
4
min(iterable: Iterable) → object[source]

Examples

>>> ScaleRange(low=0, high=5).min([3, 1, 4])
1
ne(one: object, another: object) → bool

Test “not equal”. Cf. lt().

sort(some_list: list, reverse: bool = False) → None[source]

Examples

>>> some_list = [3, 1, 4]
>>> ScaleRange(low=0, high=5).sort(some_list)
>>> some_list
[1, 3, 4]