iget

negmas.generics.iget(x: Union[Mapping, Sequence], _key: Any, default=None)Any[source]

Get an item from an IterableMapping

Parameters
  • x – the generic mapping

  • _key – key (must be immutable)

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

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: