python的一组很好的实用函数

understreck的Python项目详细描述


欠速

https://img.shields.io/pypi/v/understreck.svghttps://travis-ci.com/cfarvidson/understreck.svg?branch=masterDocumentation StatusCode style: black

一组不错的python实用函数

功能

  • 使用嵌套的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"

学分

我得把这个项目归功于我的灵感

这个包是用Cookiecutteraudreyr/cookiecutter-pypackage项目模板创建的。

历史记录

未发布

0.5.0(2019-05-03)

  • 更新开发依赖项
  • 移动到新存储库

0.4.0(2019-05-03)

  • 添加带缩进的Understreck.strip

0.3.0(2019-05-03)

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上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何向第二个组合框模型项添加数组值从第一个组合框所选项获取数组名称?   使用Java与WebSphere的SSL握手错误   eclipse线程“main”Java中的第一个Java程序异常。lang.NoClassDefFoundError   java将Javafx应用作为Web应用移植的最佳方式   IDE的java右JVM文件夹   java如何在基本适配器中停止文本到语音   java If block使用substring和equals方法以假值执行   在本例中,如何在java中返回多个值?   java第二个主类在maven构建期间覆盖第一个主类   如何在java中设置运行时ArrayList的泛型类型?   java从主机读取文件