tkmilan.util#
Utility functions.
Module Attributes
Get the tk version as an integer tuple. |
Functions
|
Least Common Multiple: Multiple number |
|
Least Common Multiple: Single Pair |
Classes
|
A monotonic counter, to be used by calling the instance. |
|
A mix of |
- class tkmilan.util.CCounter(default: int = 0)#
Bases:
objectA monotonic counter, to be used by calling the instance.
This is to be used like this:
cnt = Counter() print('Current:', cnt()) # Current: 1 print('Current:', cnt()) # Current: 2 print('Current:', cnt()) # Current: 3 assert cnt.count == 3
- class tkmilan.util.ReorderableDict(initialdata: Mapping[RDkT, RDvT] | None = None)#
Bases:
UserDict,Generic[RDkT,RDvT]A mix of
dictandlist, a mapping that allows for reordering the key list, but still allows for fast random access to the values.Stores a regular
dict, plus a separate copy of the keys as alist. These are synchronized.Should be used as a regular
dict, and there are special functions for manipulating the key order.See
indexandat,insertandmove.- at(index: int) RDkT#
Return the
keyatindexon the ordered key list.Supports all upstream functionality, such as negative indexes to count from the end of the list. Slices are technically supported, but frowned upon.
- Parameters:
index (int) – Index to locate the key
- Returns:
If the
indexis out of bounds, raisesIndexError(just like the upstream function). Otherwise, return the key located in that index.The following invariant holds:
self.index(self.at(X)) == X
- Return type:
RDkT
See also
See the upstream function list.__getitem__
- clear() None#
Remove all items from the mapping.
See also
See the upstream function
dict.clear.
- index(key: RDkT, *args: Any) int | None#
Return the first index of the
keyin the ordered key list.- Parameters:
key (RDkT) – The key to search for.
args (Any) – Passed to the upstream function
- Returns:
If the
keyis not present in the mapping, returnNone. Otherwise, return the first index on the ordered key list.- Return type:
int | None
See also
See the upstream function list.index
- insert(index: int, key: RDkT, value: RDvT) None#
Insert a key-value pair before the given index.
To append a key-value pair, use
self[key] = value. To move an existing key, usemove.- Parameters:
index (int) – Index to insert the given key-value pair.
key (RDkT) – The key to insert
value (RDvT) – The value to insert
See also
See the upstream function list.insert.
- items() Iterator[Tuple[RDkT, RDvT]]#
Return an iterator of key-value tuples, using the ordered key list.
See also
See the documentation on the upstream function
dict.items.Note
The return value is technically different from the upstream function, but it should not matter in practice.
- keys() Iterable[RDkT]#
Return an iterator of keys, using the defined order.
See also
See the documentation on the upstream function
dict.keys.Note
The return value is technically different from the upstream function, but it should not matter in practice.
- tkmilan.util.lcm_multiple(*numbers)#
Least Common Multiple: Multiple number
Note
Python 3.9 has math.lcm.
- tkmilan.util.lcm_single(a, b)#
Least Common Multiple: Single Pair
- tkmilan.util.TK_VERSION = (8, 6)#
Get the tk version as an integer tuple.
Similar to
sys.version_info.