gemd.entity.case_insensitive_dict module

class gemd.entity.case_insensitive_dict.CaseInsensitiveDict(seq: Optional[Sequence] = None, **kwargs)

Bases: dict

A dictionary in which the keys are case-insensitive.

It is initialized the same way as a typical dict, but the values can be accessed without regard to key case. The value associated with key “Key” can also be accessed with “key” or “KEY” or “kEy”.

Parameters
  • seq (iterable or mapping, optional) – The key-value pairs of the dictionary. Can either be a mapping object with (key, value) pairs, or an iterable of tuples of the form (key, value).

  • **kwargs (keyword args, optional) – An alternative way of initializing the dictionary with key-value pairs. Example: CaseInsensitiveDict(one=1, two=”two”).

clear() None

Remove all items from the dictionary.

copy() CaseInsensitiveDict

Return a shallow copy of the dictionary.

Returns

A duplicate of the dictionary

Return type

CaseInsensitiveDict

fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key: str, default: Optional[Any] = None) Any

Get the value for a given case-insensitive key.

Parameters
  • key (str) – The key to look up (possibly with a different casing).

  • default (Any) – The result to return if the key is not present.

Returns

The value associated with the case-insensitive version of key, or None if key is not present.

Return type

Any

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(key: str, default=<object object>) Any

Remove and return the value for a given key from the dictionary.

If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.

Parameters
  • key (str) – The key to look up (possibly with a different casing).

  • default (Any) – The result to return if the key is not present.

Returns

The value associated with the case-insensitive version of key, or None if key is not present.

Return type

Any

popitem() Tuple

Remove and return a (key, value) pair from the dictionary.

popitem() is useful to destructively iterate over a dictionary, as often used in set algorithms. If the dictionary is empty, calling popitem() raises a KeyError.

Changed in version 3.7: LIFO order is now guaranteed. In prior versions, popitem() would return an arbitrary key/value pair.

Returns

The key-value pair

Return type

Tuple(str, Any)

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update(mapping: Optional[Mapping[str, Any]] = None, **kwargs) None

Update the dictionary with the key/value pairs from other, overwriting existing keys.

update() accepts either another dictionary object or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).

Parameters
  • mapping (Mapping) – The set of (key, value) pairs to store

  • kwargs ((str, Any)) – Alternatively, the set of keyword arguments

values() an object providing a view on D's values