zoukankan      html  css  js  c++  java
  • python -- itools.functoolz,itoolz.dicttoolz

    2019.9.26:

    学习内容:functoolz、dicttoolz


     二、functoolz:

    1、pipe(data, *funcs):

      pipe(data,f,g,h) 等价于 h(g(f(data)))

      类似于UNIX的管道一样。

    2、juxt(*funcs)(data):

      接受几个函数并返回一个元组,保存data分别在这几个函数的结果。方便多个函数的比较。

      

    3、do(func, x):

      用于记录进入func的输入,返回列表。

    4、curry(*args, **kwargs):

      两种用法,可以作为装饰器,在函数定义时声明。目的是允许这个函数可以不用一次性传入全部参数。类似于偏函数使用

    5、flip(func, para):

      针对内置函数的curry

    6、excepts(exc, func, handler = <function return_none>):

      用于捕获一场并分派给处理程序。就是一个function的try / except块 

      例如: list.index(a) 方法是给a返回在list的位置,如果没有就发起一个异常。


    三、dicttoolz:

    1、merge(*dicts, **kwargs):

      合并两个字典,重复key的以右边字典为准,超好用~

    2、merge_with(func,*dicts, **kwargs):

      重复key会按照func规则进行value的处理 

    3、valmap(func,d, factory = <type='dict'>):

      对字典的value做map映射。

    4、keymap(func,d, factory = <type='dict'>):

      对字典的key做map映射。

    5、itemmap(func,d, factory = <type='dict'>):

      对字典的key和value做映射,通常为reverse翻转键值。

     

    7、valfilter(func,d, factory = <type='dict'>):

      对value按func规则做过滤。

    8、keyfilter(func,d, factory = <type='dict'>):

      对key按func规则做过滤。

    9、keyfilter(func,d, factory = <type='dict'>):

      同时对key和value按func规则做过滤。

    10、assoc(dict,key,value, factory = <type='dict'>):

      原字典不变,返回的是新字典。给出的key如果dict有,则赋予新value,无则新增键值对

    11、dissoc(dict,*key):

      返回一个删除了给定key的新字典。原字典不动。

  • 相关阅读:
    Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA
    mysql使用instr
    swagger错误:Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body
    java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result异常的解决方法
    平行四边形
    transition
    transform
    box-shadow
    text-shadow文字阴影
    linear-gradient线性渐变
  • 原文地址:https://www.cnblogs.com/marvintang1001/p/11589966.html
Copyright © 2011-2022 走看看