[READ-ONLY] Mirror of https://github.com/probablykasper/deep-filter. pypi.org/project/deep-filter
package
0

Configure Feed

Select the types of activity you want to include in your feed.

vidl now adds metadata to files

Kasper (Oct 2, 2018, 9:18 PM +0200) 012ae53c ff4c4cdb

+46 -7
+26
README.md
··· 1 + # deep-filter 2 + A simple package that filters out values from dicts/lists, including all dicts/lists nested within it. 3 + 4 + # Usage 5 + ```python 6 + from deep_filter import deep_filter 7 + x = { 8 + 'nope': 69, 9 + 'yep': [ 10 + 69, 11 + {'maybe': None}, 12 + 99 13 + ] 14 + } 15 + def filter_func: 16 + return value != 69 17 + result = deep_filter(x, filter_func) 18 + print(result) 19 + # {'yep': [{}, 99]} 20 + ``` 21 + 22 + #### deep_filter(dict_or_list, filter_func=default_filter_func) 23 + - **dict_or_list**: A dictionary or list 24 + - **filter_func**: An optional callback function. It will take a value as an argument, and return `True` if the value will be kept and `False` if not. If omitted, `None` values will be filtered out. 25 + 26 + Returns your dict or list, filtered.
+19 -3
deep_filter.py
··· 1 - def main(): 2 - print(55) 3 - return 999 1 + def iterate(obj): 2 + if type(obj) == dict: 3 + return obj.items() 4 + elif type(obj) == list: 5 + return enumerate(obj) 6 + 7 + def default_filter_function(value): 8 + return value != None 9 + def deep_filter(obj, filter_func=default_filter_function): 10 + if type(obj) == dict: 11 + obj = {key:value for key,value in obj.items() if filter_func(value)} 12 + elif type(obj) == list: 13 + obj = [value for value in obj if filter_func(value)] 14 + 15 + for key, value in iterate(obj): 16 + if type(value) not in [dict, list]: 17 + continue 18 + obj[key] = deep_filter(value) 19 + return obj
dist/deep-filter-1.0.0.tar.gz

This is a binary file and will not be displayed.

dist/deep_filter-1.0.0-py2.py3-none-any.whl

This is a binary file and will not be displayed.

+1 -4
pyproject.toml
··· 15 15 python = "*" 16 16 17 17 [tool.poetry.dev-dependencies] 18 - pylint = "^2.1" 19 - 20 - [tool.poetry.scripts] 21 - pawaka = 'deep_filter:main' 18 + pylint = "^2.1"