Python dictionary with broadcast support.
Behaves like a regular dictionary.
Allows to apply operations to all its values at once. Whithout loops, whithout dict comprehension.
pip install bcdict
from bcdict import BCDict
>>> d = BCDict({"a": "hello", "b": "world!"})
>>> d
{'a': 'hello', 'b': 'world!'}
Regular element access:
>>> d['a']
'hello'
Regular element assignments
>>> d['a'] = "Hello"
>>> d
{'a': 'Hello', 'b': 'world!'}
Calling functions:
>>> d.upper()
{'a': 'HELLO', 'b': 'WORLD!'}
Slicing:
>>> d[1:3]
{'a': 'el', 'b': 'or'}
Applying functions:
>>> d.pipe(len)
{'a': 5, 'b': 6}
When there is a conflict between an attribute in the values and an attribute in
BCDict
, use the attribute accessor explicitly:
>>> d.a.upper()
{'a': 'HELLO', 'b': 'WORLD!'}
Slicing with conflicting keys:
>>> n = BCDict({1:"hello", 2: "world"})
>>> n[1]
'hello'
>>> # Using the attribute accessor:
>>> n.a[1]
{1: 'e', 2: 'o'}
See the introduction notebook and other examples.
Also check out the full documentation on bcdict.readthedocs.io.
- feature: broadcast attribute and item assignment
- fix: broadcast slicing with
.a
accessor
- fix: unpickling causes recursion error
- docs: improve the documenation
- fix: sphinxcontrib-mermaid gets installed as default dependency, should be dev dependency
- new functions
eq()
andne()
for equality/inequality with broadcast support
- new functions in
bcdict
package:apply()
broadcast()
broadcast_arg()
broadcast_kwarg()
- docs: write some documentation and host it on readthedocs
- remove
item()
function. Use.a[]
instead.
- initial release
Original repository: https://github.com/mariushelf/bcdict
Author: Marius Helf (helfsmarius@gmail.com)