各种dict、list和其他数据结构的Python函数。

datafunc的Python项目详细描述


数据函数

用于dict、list和其他数据结构的各种函数的Python包。在

Actively MaintainedMIT LicensePyPI pyversions

变更日志

  • ^{str1}$11/17/2020-0.0.4:添加缺少的类型注释。生成文档。在
  • ^{str1}$11/17/2020-0.0.3:添加了duplicate()和{}方法。添加了一些缺少的类型声明。在
  • 11/15/2020-0.0.2:类型注释和次要重构。在
  • ^{str1}$11/15/2020-0.0.1:初始方法。在

参考文献

展平

flatten(var:object)->Data

遍历dict-like对象并返回一个包含all的新对象 相同的值,但只有一层深。在

参数

  • var:要展平的类Dict变量。在

返回

像dict一样的数据对象。在

iterable

^{pr 2}$

Determine whether or not the input variable is iterable.

Arguments:

  • ^{}: Any

Returns:

Boolean

listlike

^{pr 3}$

Determine if the input variable is list-like (Not a str, not dict-like, but is iterable)

Arguments:

  • ^{}: Any

Returns:

Boolean

mo_dotian

^{pr 4}$

Determine whether or not the input var is a mo-dots type.

Arguments:

  • ^{}: Any

Returns:

Boolean

apply_if

^{pr 5}$

Apply func_to_apply() to var if condiction() else apply else_func()

Arguments:

  • ^{}: Callable to pass var to if condition(var) return true
  • ^{}: Variable to test against condition and return through func_to_apply() or else_func()
  • ^{}: Callable to test var against. Should return a Boolean.
  • ^{}: Callable to return var through if condition(var) returns False.

Returns:

func_to_apply(var) if condition(var) returns True, otherwise else_func(var)

dictlike

^{pr 6}$

Determine whether or not var is dict-like (Can contain dict-like items).

Arguments:

  • ^{}: Any variable to check

Returns:

Boolean

nestable

^{pr 7}$

Will return True if input var is either list-like or dict-like.

Arguments:

  • ^{}: Any input variable.

Returns:

Boolean

jsonify_nestable_vals

^{pr 8}$

Convert any nestable (Dict-like or list-like) to a dict-like mo-dots Data object of obj's values as JSON strings.

Arguments:

  • ^{}: Any nestable variable.

Returns:

A dict-like mo-dots Data object of obj's values as JSON strings.

compare

^{pr 9}$

Compare dict-like variable d1 to dict-like variable d2 and return a dict-like mo-dots Data object of what's been added, removed, modified, or remained equal in d2

Arguments:

  • ^{}: Dict-like variable as the base variable.
  • ^{}: Dict-like variable to compare/contrast to d1

Returns:

Dict-like mo-dots Data object of differences between d1 and d2.

function_of

^{pr 10}$

Determine whether or not a function's (func) name exists in tuple of strings (func_names).

Arguments:

  • ^{}: The callable function to test.
  • ^{}: Tuple of function names as strings ("func1", "func2", "func3,)

Returns:

Boolean True (func is of func_names) or False (func is not of func_names)

basevals

^{pr 11}$

This method receives a dict and list of attributes to return the innermost value of the given dict-like var. This function seems stupid and I don't recall what it was for.

vivify

^{pr 12}$

Adds the last attr variable passed to the dict-like "var" in the hierarchy mentioned via the prior *attrs For ex: vivify(animals, "cat", "leg","fingers", 4) is equivalent to animals["cat"]["leg"]["fingers"]=4 This method creates necessary objects until it reaches the final depth This behaviour is also known as autovivification and plenty of implementation are around This implementation addresses the corner case of replacing existing primitives https://gist.github.com/hrldcpr/2012250#gistcomment-1779319

复制

duplicate(data:object)->object

方便方法复制.deepcopy()

参数

返回

数据的深层拷贝。在

添加同级
add_sibling(data:object,node_path:List,new_key:str,new_data:Any,_i:int=0)

用于添加同级数据节点的遍历安全方法。在

参数

  • data:正在遍历的数据对象。在
  • node_path:指向要创建的节点的路径段列表 兄弟姐妹。与遍历()的节点路径相同
  • new_key:要创建的同级键。在
  • new_data:要存储在密钥处的新数据。在
  • _i:节点路径迭代器的深度。在

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

推荐PyPI第三方库


热门话题
java Jsonify使用Jackson来定义嵌套对象   在Swing中禁用java图形调试   java Selenium Webdriver拖放在Jenkins上不起作用   java我对一个显示器的问题有一个非常不切实际的询问   java增强的“for”循环导致ArrayIndexOutOfBoundsException   ArrayAdapter适用于Java中的安卓编程,字符串数组   linux在Ubuntu上通过PulseAudio播放Java音频文件时出错   java在Spring应用程序中加载内部(类路径)和外部属性文件   java使用Maven连接到mySQL   Java应用程序的设计   websocket在电报api java中与dc的连接   java XMLStreamException,因为xml中的(&N)   java从控制台输出到JTextArea   Java导出文本文件   java实现parseInt方法   java为什么servlet容器会同步对特定资源/servlet的多个请求的访问?   循环中的Java“while”变量   用Java编程一个国际象棋游戏,gameOver布尔不起作用   java如何获得真正的JPanel大小?