bdict

class bdict(seq=None, **kwargs)[source]

Bases: UserDict

Returns a new dictionary initialized from an optional positional argument, and a possibly empty set of keyword arguments.

Each key: value pair is entered into the dictionary in both directions, so you can perform lookups with either the key or the value.

If no positional argument is given, an empty dictionary is created.

If a positional argument is given and it is a mapping object, a dictionary is created with the same key-value pairs as the mapping object. Otherwise, the positional argument must be an iterable object. Each item in the iterable must itself be an iterable with exactly two objects. The first object of each item becomes a key in the new dictionary, and the second object the corresponding value.

If keyword arguments are given, the keyword arguments and their values are added to the dictionary created from the positional argument.

If an attempt is made to add a key or value that already exists in the dictionary a ValueError will be raised.

Keys or values of None, True and False will be stored internally as "_None", "_True" and "_False" respectively

Methods:

__contains__(key)

Return key in self.

__delitem__(key)

Delete self[key].

__getitem__(key)

Return self[key].

__setitem__(key, val)

Set self[key] to value.

clear()

Removes all items from the bdict.

get(k[, default])

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

items()

Returns a set-like object providing a view on the bdict's items.

keys()

Returns a set-like object providing a view on the bdict's keys.

values()

Returns an object providing a view on the bdict's values.

__contains__(key)[source]

Return key in self.

Parameters

key (object)

Return type

bool

__delitem__(key)[source]

Delete self[key].

Parameters

key (~KT)

__getitem__(key)[source]

Return self[key].

Parameters

key (~KT)

Return type

~VT

__setitem__(key, val)[source]

Set self[key] to value.

Parameters
  • key

  • val

clear()[source]

Removes all items from the bdict.

get(k, default=None)[source]

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

Parameters
  • k – The key to return the value for.

  • default – The value to return if key is not in the dictionary. Default None.

Overloads
items()[source]

Returns a set-like object providing a view on the bdict's items.

Return type

AbstractSet[Tuple[~KT, ~VT]]

keys()[source]

Returns a set-like object providing a view on the bdict's keys.

Return type

AbstractSet[~KT]

values()[source]

Returns an object providing a view on the bdict's values.

Return type

ValuesView[~VT]