gget

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

Get an item from an IterableMapping

Parameters:
Return type:

Any

Examples

Example with a list

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

Example with a dictionary

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

Example with a tuple

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

Example with a generator

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

Returns: