python的一组很好的实用函数
understreck的Python项目详细描述
欠速
一组不错的python实用函数
- 自由软件:GNU通用公共许可v3
- 文档:https://understreck.readthedocs.io。
功能
- 使用嵌套的get函数对嵌套字典执行安全get
- 将列表分成块
嵌套获取示例:
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
块示例:
import understreck as _ to_chunk = ["one", "two", "three", "four", "five"] result = _.chunks.split(to_chunk, 2) # result == [["one", "two", "three"], ["four", "five"]]
过滤示例:
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}]
条形缩进示例:
import understreck as _ def some_function(): to_strip = """This is a multi-line string""" _.strip(to_strip) # "This is a\nmulti-line\nstring"
历史记录
未发布
0.5.0(2019-05-03)
- 更新开发依赖项
- 移动到新存储库
0.4.0(2019-05-03)
- 添加带缩进的Understreck.strip
0.3.0(2019-05-03)
- 添加understreck.filter,灵感来自https://lodash.com/docs/4.17.11#filter
- 更新了travis按钮URL
- 在自述文件中将嵌套的get替换为get(嵌套仍然有效)
- 黑色格式
0.2.1(2018-12-10)
- 添加Understreck.chunks
0.2.0(2018-11-12)
- 将get添加为嵌套get的别名
0.1.1(2018-11-02)
- 更新自述文件
0.1.0(2018-11-02)
- pypi上的第一个版本。