collections¶
Specialised container datatypes
-
class
coinflip.collections.
Bins
(intervals: Iterable[numbers.Real])[source]¶ Mapping that initialises intervals as empty bins
If a key is accessed that does not exist, the nearest interval is used.
- Parameters
intervals (
Iterable[Real]
) – Non-existent keys will round to the closest of these intervals
Examples
>>> bins = Bins([-6, -3, 0, 3, 6]) >>> bins {-6: 0, -3: 0, 0: 0, 3: 0, 6: 0} >>> bins[3] += 1 # n = 3 >>> bins {-6: 0, -3: 0, 0: 0, 3: 1, 6: 0} >>> bins[7] += 1 # n = 6 >>> bins[11] += 1 # n = 6 >>> bins[6.5] += 1 # n = 6 >>> bins {-6: 0, -3: 0, 0: 0, 3: 1, 6: 3} >>> bins[-1000000] += 1 # n = -6 >>> bins {-6: 1, -3: 0, 0: 0, 3: 1, 6: 3} >>> bins[0.5] += 1 # n = 0 >>> bins {-6: 1, -3: 0, 0: 1, 3: 1, 6: 3} >>> del bins[6] {-6: 1, -3: 0, 0: 1, 3: 4}
-
class
coinflip.collections.
defaultlist
(default_factory: Optional[Callable] = None)[source]¶ A list with default values
- Parameters
default_factory (
Callable
, optional)
-
class
coinflip.collections.
FloorDict
(dict: Dict)[source]¶ Mapping where invalid keys floor to the smallest real key
If a key is accessed that does not exist, the nearest real key that is the less-than of the passed key is used.
- Parameters
dict (
Dict
) – Dictionary containing the key-value pairs to be floored to