Skip to content

shinaji/wdict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
shinaji
Aug 13, 2020
dc3c6cb · Aug 13, 2020

History

27 Commits
Aug 13, 2020
Aug 13, 2020
Mar 1, 2018
Apr 5, 2018
Aug 13, 2020
Mar 1, 2018

Repository files navigation

wdict

The Dictionary class contains filtering methods.

Install

pip install --upgrade wdict

Features

  • Filter dicts based on its child value by "where" method
  • Filter dicts based on its keys by "has_child"", "exclude" and "extract" method
  • Support specific depth key dropping
  • Concatenate dicts with "+" operator
  • Attribute-style access

Operators for the "where" method

  • "==", ">=", "<=", "!=", "<", ">"
  • "in", "not in"
  • "has", "does not have"
  • "has any", "does not have any"
  • "has all", "does not have all"
  • "subset of"

Usage

>>> from wdict import Dict as WD

Examples

See the test code

>>> a = WD({"a": 1}) 
>>> b = WD({"a": 2, "b": 2})
>>> a + b
Dict([('a', [1, 2]), ('b', 2)])
>>> (a + b).a
[1, 2]
>>> (a + b)["a"]
[1, 2]

>>> a = WD({"a": 1, "b": {"child": 1}}) 
>>> a.where("child", "==", 1)
Dict([('b', Dict([('child', 1)]))])

>>> a = WD({"a": 1, "b": {"child": 1}}) 
>>> a.exclude(["b"])
Dict([('a', 1)])

>>> a = WD({"a": {"c": 1}}) 
>>> b = WD({"a": {"d": 2}})
>>> print(a + b)
{"a": {"c": 1, "d": 2}}
>>> print(sum([a, b]))
{"a": {"c": 1, "d": 2}}

>>> a = WD({"a": 1}) 
>>> b = WD({"b": 2})
>>> a += b
>>>print(a)
{"a": 1, "b": 2}

>>> a = WD({"a": 1, "b": "str a"}) 
>>> b = WD({"a": [2, 3], "b": "str b"})
>>> (a + b).a
[1, [2, 3]]
>>> (a + b).b
['str a', 'str b']

>>> a = WD({"a": 1}) 
>>> b = WD({"a": {"b": 1}})
>>> (a + b).a
[1, Dict([('b', 1)])]

About

extended python dictionary class

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages