BallotOneName¶
-
class
whalrus.
BallotOneName
(b: object, candidates: set = None)[source]¶ A ballot in a mono-nominal context (typically plurality or veto).
- Parameters
b (candidate or None) – None stands for abstention.
candidates (set) – The candidates that were available at the moment when the voter cast her ballot.
Examples
>>> ballot = BallotOneName('a', candidates={'a', 'b', 'c'}) >>> print(ballot) a
>>> ballot = BallotOneName(None, candidates={'a', 'b', 'c'}) >>> print(ballot) None
-
property
candidates_in_b
¶ The candidate that is explicitly mentioned in the ballot.
This is a singleton with the only candidate contained in the ballot (or an empty set in case of abstention).
Examples
>>> BallotOneName('a', candidates={'a', 'b', 'c'}).candidates_in_b {'a'} >>> BallotOneName(None, candidates={'a', 'b', 'c'}).candidates_in_b {}
- Type
-
property
candidates_not_in_b
¶ The candidates that were available at the moment of the vote, but are not explicitly mentioned in the ballot.
Examples
>>> BallotOneName('a', candidates={'a', 'b', 'c'}).candidates_not_in_b {'b', 'c'}
- Type
-
first
(candidates: set = None, **kwargs) → object[source]¶ The first (= most liked) candidate.
In this parent class, by default, the ballot is considered as a plurality ballot, i.e. the candidate indicated is the most liked.
- Parameters
candidates (set of candidates) –
kwargs –
priority: a
Priority
. Default:Priority.UNAMBIGUOUS
.
- Returns
The first (= most liked) candidate.
- Return type
candidate
Examples
>>> BallotOneName('a', candidates={'a', 'b', 'c'}).first() 'a' >>> BallotOneName('a', candidates={'a', 'b', 'c'}).first(candidates={'b', 'c'}, ... priority=Priority.ASCENDING) 'b'
-
last
(candidates: set = None, **kwargs) → object[source]¶ The last (= most disliked) candidate.
In this parent class, by default, the ballot is considered as a plurality ballot, i.e. the candidate indicated is the most liked.
- Parameters
candidates (set of candidates) –
kwargs –
priority: a
Priority
. Default:Priority.UNAMBIGUOUS
.
- Returns
The last (= most disliked) candidate.
- Return type
candidate
Examples
>>> BallotOneName('a', candidates={'a', 'b'}).last() 'b' >>> BallotOneName('a', candidates={'a', 'b', 'c'}).last(priority=Priority.ASCENDING) 'c'
-
restrict
(candidates: set = None, **kwargs) → whalrus.ballots.ballot_one_name.BallotOneName[source]¶ Restrict the ballot to less candidates.
- Parameters
candidates (set of candidates) – It can be any set of candidates, not necessarily a subset of
self.candidates
). Default:self.candidates
.kwargs –
priority: a
Priority
. Default:Priority.UNAMBIGUOUS
.
- Returns
The same ballot, “restricted” to the candidates given.
- Return type
Examples
>>> BallotOneName('a', candidates={'a', 'b'}).restrict(candidates={'b'}) BallotOneName('b', candidates={'b'}) >>> BallotOneName('a', candidates={'a', 'b', 'c'}).restrict(candidates={'b', 'c'}, ... priority=Priority.ASCENDING) BallotOneName('b', candidates={'b', 'c'})