BallotPlurality

class whalrus.BallotPlurality(b: object, candidates: set = None)[source]

A plurality ballot.

Examples

>>> ballot = BallotPlurality('a', candidates={'a', 'b', 'c'})
>>> print(ballot)
a
>>> ballot = BallotPlurality(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

NiceSet

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

NiceSet

first(candidates: set = None, **kwargs) → object

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
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

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
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

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

Returns

The same ballot, “restricted” to the candidates given.

Return type

BallotOneName

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'})