A collection of nice utility functions for python
Project description
Understreck
A collection of nice utility functions for python
Free software: GNU General Public License v3
Documentation: https://understreck.readthedocs.io.
Features
Perform a safe get on a nested dictionary with the nested_get function
Split a list into chunks
Nested Get example:
import understreck as _ test_dictionary = { "the_top_level": { "second_level": {"third_level": "it works", "third_level_sibling": False} } } # Using dot delimited strings result = _.get(test_dictionary, "the_top_level.second_level.third_level") # result = "it works" result = _.get(test_dictionary, "the_top_level.second_level.DOES_NOT_EXIST") # result = None # Using a list or tuple result = _.get(test_dictionary, ["the_top_level", "second_level", "third_level"]) # result = "it works" result = _.get(test_dictionary, ["the_top_level", "second_level", "DOES_NOT_EXIST"]) # result = None
Chunks example:
import understreck as _ to_chunk = ["one", "two", "three", "four", "five"] result = _.chunks.split(to_chunk, 2) # result == [["one", "two", "three"], ["four", "five"]]
Filter example:
import understreck as _ users = [ {"user": "barney", "age": 36, "active": True}, {"user": "fred", "age": 40, "active": False}, ] # Using a lambda function result = _.filter(users, lambda x: not x.get("active")) # result == [{"user": "fred", "age": 40, "active": False}] # Using partial dictionary result = _.filter(users, {"age": 36, "active": True}) # result == [{"user": "barney", "age": 36, "active": True}] # Using a list with a property name and value result = _.filter(users, ["active", False]) # result == [{"user": "fred", "age": 40, "active": False}] # Using a list with a property name. The value must be truthy. result = _.filter(users, ["active"]) # result == [{"user": "barney", "age": 36, "active": True}]
Strip indents example:
import understreck as _ def some_function(): to_strip = """This is a multi-line string""" _.strip(to_strip) # "This is a\nmulti-line\nstring"
Credits
I have to credit the Lodash project for inspiration!
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
Unreleased
0.5.0 (2019-05-03)
Updates dev dependencies
Moves to the new repository
0.4.0 (2019-05-03)
Adds Understreck.strip that strips indents
0.3.0 (2019-05-03)
Adds Understreck.filter with inspired by https://lodash.com/docs/4.17.11#filter
Updated the travis button URL
Replaced nested_get with get in the README. (nested_get still works)
Black formatting
0.2.1 (2018-12-10)
Add Understreck.chunks
0.2.0 (2018-11-12)
Add get as an alias for nested get
0.1.1 (2018-11-02)
Update the readme
0.1.0 (2018-11-02)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for understreck-0.5.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6318033fd0ddf11aa9999b9408906d317df3ca1e04cc48a32b108a7472a35c38 |
|
MD5 | 23eac81bec88285131ff05f5f1be94cf |
|
BLAKE2b-256 | db0c3c8546711759fd24a3af9193ad8e4cf20ba4099d5371b2a9a3e3733e0913 |