Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 1.12 KB

pstar_defaultpdict___getitem__.md

File metadata and controls

33 lines (23 loc) · 1.12 KB

pstar.defaultpdict.__getitem__(self, key)

Subscript operation. Keys can be any normal dict keys or lists of such keys.

Examples:

pd = defaultpdict(int).update(foo=1, bar=2.0, baz='three')
assert (pd['foo'] == pd.foo == 1)
assert (pd[['foo', 'bar', 'baz']].aslist() == [1, 2.0, 'three'])

When indexing with a list, the returned plist is rooted at a plist of KeyValue namedtuples, making it easy to recover the keys that gave the values, and allows the plist to be turned back into a corresponding pdict:

assert (pd[['foo', 'baz']].root().aslist() ==
        [('foo', 1), ('baz', 'three')])
assert (pd[['foo', 'baz']].pdict() ==
        dict(foo=1, baz='three'))

Args:

key: Any hashable object, or a list of hashable objects.

Returns:

Either the value held at key, or a plist of values held at each key in the list of keys, when called with a list of keys.