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 Play Framework 2.1中的简单搜索?   java:Springbeans的真正工作原理   java不能从字符串中提取数字   不同管道中的java共享ExecutionHandler   在Java中,如何为扩展comparator的类实现多个comparator方法?   通用混沌Java   java问题:从自定义类获取要添加到驱动程序类的形状   java如何利用HikariCP和Hibernate?   eclipse如何执行Java应用程序?   用户界面Java Swing:如何将JLabel的文本绑定到JTable选定行中的列?   java替换JPanel元素而不添加到面板的末尾?   java Sets根据action命令在按钮组中选择了特定的jradiobutton   在java中如何将从控制台添加的字符串中的元素添加到列表中   处理未在浏览器上运行的Java签名小程序   java如何在我的安卓应用程序中单击任意按钮时禁用音频音调?   编码如何在Java中将十六进制转换为utf8编码的字符串   java JSF Spring安全集成问题   java如何更正Oracle for Windows中的字符?   java Spark结构化流媒体:当前批次落后   java Hibernate根据最匹配的条件排序结果