ScaleFromList

class whalrus.ScaleFromList(levels: list)[source]

Scale derived from a list.

Parameters

levels (list) – The list of levels, from the worst to the best.

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

Examples

>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> scale.argsort(['Good', 'Bad', 'Excellent'])
[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
>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> scale.high
'Excellent'
le(one: object, another: object) → bool

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

property low
>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> scale.low
'Bad'
lt(one: object, another: object) → bool[source]
>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> scale.lt('Medium', 'Excellent')
True
max(iterable: Iterable) → object[source]

Examples

>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> scale.max(['Good', 'Bad', 'Excellent'])
'Excellent'
min(iterable: Iterable) → object[source]

Examples

>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> scale.min(['Good', 'Bad', 'Excellent'])
'Bad'
ne(one: object, another: object) → bool

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

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

Examples

>>> scale = ScaleFromList(['Bad', 'Medium', 'Good', 'Very good', 'Excellent'])
>>> some_list = ['Good', 'Bad', 'Excellent']
>>> scale.sort(some_list)
>>> some_list
['Bad', 'Good', 'Excellent']