iget

negmas.generics.iget(x, _key, default=None)[source]

Get an item from an IterableMapping

Parameters:
  • x (Union[Mapping, Sequence]) – the generic mapping

  • _key (Any) – key (must be immutable)

  • default – default value if no value attached with the key is found

Return type:

Any

Examples

Example with a list

>>> [iget([10, 20, 30], _) for _ in (0, 2, 1, -1, 4)]
[10, 30, 20, 30, None]

Example with a dictionary

>>> [iget({"a": 10, "b": 20, "c": 30}, _) for _ in ("a", "c", "b", -1, "d")]
[10, 30, 20, None, None]

Example with a tuple

>>> [iget((10, 20, 30), _) for _ in (0, 2, 1, -1, 4)]
[10, 30, 20, 30, None]

Example with a generator

>>> [iget(range(10, 40, 10), _) for _ in (0, 2, 1, -1, 4)]
[10, 30, 20, 30, None]

Returns: