PriorityUnambiguous¶
-
class
whalrus.
PriorityUnambiguous
[source]¶ When there are two elements or more, raise a ValueError.
Examples
>>> try: ... Priority.UNAMBIGUOUS.choice({'a', 'b'}) ... except ValueError: ... print('Cannot choose') Cannot choose >>> try: ... Priority.UNAMBIGUOUS.sort({'a', 'b'}) ... except ValueError: ... print('Cannot sort') Cannot sort
-
choice
(x: Union[set, list], reverse: bool = False) → object¶ Choose an element from a list, set, etc.
- Parameters
x (list, set, etc.) – The list, set, etc where the element is to be chosen.
reverse (bool) – If False (default), then we choose the “first” or “best” element in this priority order. For example, if this is the ascending priority, we choose the lowest element. If True, then we choose the “last” or “worst” element. This is used, for example, in
RuleVeto
.
- Returns
The chosen element (or None). When
x
is empty, return None. Whenx
has one element, return this element.- Return type
object
-
compare
(c, d) → int[source]¶ Compare two candidates.
- Parameters
c (candidate) –
d (candidate.) –
- Returns
0 if c = d, -1 if the tie is broken in favor of c over d, 1 otherwise.
- Return type
int
-
sort
(x: Union[set, list], reverse: bool = False) → Optional[list]¶ Sort a list, set, etc.
The original list
x
is not modified.- Parameters
x (list, set, etc.) –
reverse (bool) – If True, we use the reverse priority order.
- Returns
A sorted list (or None).
- Return type
list or None
-
sort_pairs_rp
(x: Union[set, list], reverse: bool = False) → Optional[list]¶ Sort a list, set, etc. of pairs of candidates (for Ranked Pairs).
By default, it is in the normal priority order for the first element of the pair, and in the reverse priority order for the second element of the pair.
The original list
x
is not modified.- Parameters
x (list, set, etc.) –
reverse (bool) – If True, we use the reverse priority order.
- Returns
A sorted list (or None).
- Return type
list or None
-