Super Dicts¶
- class DropNoneDict(map_: Mapping = Ellipsis, *, none_condition: Any = None, **kwargs)¶
Bases:
dict
A dictionary that will automatically drop values of None.
- Parameters:
map – A Mapping to be used to instantiate the dictionary.
none_condition – What value gets auto-dropped? Defaults to None.
kwargs – The kwargs representing key-val pairs to put in the dict.
- none_if(value: Any, none_val: Any = Ellipsis, *, plug_in: Callable = Ellipsis, plug_out: str = Ellipsis) Any ¶
- Changes a value to the correct “None” value of the containing dict if it meets specified
criteria.
- Parameters:
value – The value that is being tested.
none_val – The value that should also be “None”.
plug_in – A function that should be enacted on the value if it is not “None”.
plug_out – A function of the value, which should be called (without arguments) and the result of which should be returned if the value is not “None”.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- class ListDict(key_function: Callable, values: Iterable = Ellipsis)¶
Bases:
list
A list that sort of acts like a dictionary…
- Parameters:
key_function – The function that should be called on each item to get its appropriate key.
values – The values that should be put in the list.
- append(obj) None ¶
Append an item…
- extend(iterable: Iterable) None ¶
Extend with an iterable…
- get(key: str | Tuple[str, int], default: Any | None = None) Any ¶
Gets an item from the
ListDict
by key. Will not raise an exception if the key does not exist, but will instead return default.- Parameters:
key – If this is a
str
, will attempt to find an item with a matching key. If this is atuple
consisting of astr
and anint
(n), will attempt to find items with matching keys, then return the nth element with a matching key.default – The default value to return if requested key does not exist.
- Returns:
The item at the desired key or - should the key not be found - default.
- index(value, start: int = Ellipsis, stop: int = Ellipsis) int ¶
Find the index of a value in the ListDict…
- insert(index: int, obj) None ¶
Insert a value into the ListDict…
- items() Iterable ¶
Get an iterable of the keys and values of the ListDict…
- keys() Iterable ¶
Get an iterable of the keys of the ListDict…
- pop(key: str | int | Tuple[str, int] = Ellipsis) Any ¶
- Pops an item from the
ListDict
. Will raise an exception if the item index cannot be determined.
- Parameters:
key – If this is a
str
, will attempt to find an item with a matching key. Will raise an exception if it cannot be located. If this is anint
, normal list indexing rules will be used to search. If this is atuple
consisting of astr
and anint
(n), will attempt to find items with matching keys, then return the nth element with a matching key. If omitted, the last item in the list will be returned.- Returns:
The item at the desired key/index, will also delete from the list.
- Pops an item from the
- remove(value) None ¶
Remove a value…
- values() Iterable ¶
Get an iterable of the values of the ListDict…