Skip to content

struct⚓︎

Minimal dict/struct utilities (replaces struct-tools dependency).

DotDict ⚓︎

Bases: dict

Dict that also supports attribute (dot) access.

Example:

d = DotDict(x=1, y=2) d.x 1 d.z = 3 d['z'] 3

complement(iterable, unwanteds) ⚓︎

Keep elements NOT matching any of unwanteds (via flexcomp).

Example:

complement({'a': 1, 'b': 2, 'c': 3}, ['b'])

deep_getattr(obj, name, *default) ⚓︎

Chained getattr using dot-separated name.

Example:

class A: pass a = A(); a.b = A(); a.b.c = 42 deep_getattr(a, 'b.c') 42

deep_hasattr(obj, name) ⚓︎

True if deep_getattr succeeds.

flexcomp(x, *criteria) ⚓︎

Compare x against criteria: callable, regex, or value.

Example:

flexcomp('foo', 'foo', 'bar') True flexcomp('baz', 'foo', 'bar') False

intersect(iterable, wanteds) ⚓︎

Keep elements matching any of wanteds (via flexcomp).

Example:

intersect({'a': 1, 'b': 2, 'c': 3}, ['a', 'c'])

prodct(dct) ⚓︎

Cartesian product of dict values, yielding dicts.

Example:

list(prodct(dict(n=[1, 2], c='ab'))) [{'n': 1, 'c': 'a'}, {'n': 1, 'c': 'b'}, {'n': 2, 'c': 'a'}, {'n': 2, 'c': 'b'}]

transps(thing2d, *args, **kwargs) ⚓︎

Delegate transpose to the appropriate helper based on container types.