Tally
Subclass of collections.Counter
with additional methods.
New in version 0.3.0.
Data:
Invariant |
Classes:
|
|
|
Subclass of |
Provides a dictionary interface, but with |
-
_F
= TypeVar(_F, float, int, Real) Type:
TypeVar
Invariant
TypeVar
constrained tofloat
,int
andnumbers.Real
.
-
protocol
SupportsMostCommon
[source] -
typing.Protocol
for classes which support acollections.Counter
-likecollections.Counter.most_common()
method.This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
-
class
Tally
(iterable=None, /, **kwds)[source] -
Subclass of
collections.Counter
with additional methods.New in version 0.3.0.
Methods:
Returns the
Tally
as acollections.OrderedDict
comprising the count for each element as a percentage of the sum of all elements.get_percentage
(item[, default])Returns the count for
item
, as a percentage of the sum of all elements.most_common
([n])List the
n
most common elements and their counts from the most common to the least.Attributes:
Returns the total count for all elements.
-
as_percentage
()[source] Returns the
Tally
as acollections.OrderedDict
comprising the count for each element as a percentage of the sum of all elements.Important
The sum of the dictionary’s values may not add up to exactly
1.0
due to limitations of floating-point numbers.- Return type
-
get_percentage
(item, default=None)[source] Returns the count for
item
, as a percentage of the sum of all elements.
-
-
class
Percentage
[source] -
Provides a dictionary interface, but with
collections.Counter
’scollections.Counter.most_common()
method.Represents the return type of
cawdrey.tally.Tally.as_percentage()
.Methods:
most_common
([n])List the
n
most common elements and their counts from the most common to the least.