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:
TypeVarInvariant
TypeVarconstrained tofloat,intandnumbers.Real.
-
protocol
SupportsMostCommon[source] -
typing.Protocolfor 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.Counterwith additional methods.New in version 0.3.0.
Methods:
Returns the
Tallyas acollections.OrderedDictcomprising 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
nmost 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
Tallyas acollections.OrderedDictcomprising 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.0due 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
nmost common elements and their counts from the most common to the least.