Page cover

python_pipe包管道包学习


python pipe包管道包学习

参考: https://github.com/JulienPalard/Pipe

from pipe import *

# 此处不是太理解
[1, 2, 3, 4, 5] | tee | as_list
1
2
3
4
5
Out[32]: [1, 2, 3, 4, 5]

# 将生成器转换成list列表
[1, 2, 3, 4, 5, 6] | as_list
Out[34]: [1, 2, 3, 4, 5, 6]

    
# Like Python's built-in "reversed" primitive.
[1, 2, 3] | reverse | concat
Out[52]: '3, 2, 1'
    
# Returns index of value in iterable 检索值
# 输入value start stop
[1,2,3,2,1] | index(value=2,start=2,stop=4)
Out[53]: 3
[1,2,3,2,1] | index(3)
Out[54]: 2

构造你自己的pipe管道函数

删除重复值

groupby() 对列表实现分组计算

求和和平均数

select函数,相当于map映射操作

聚合函数

筛选和过滤

take前几个元素和count生成器的长度

flatmap操作

两个列表实现zip函数

指定函数排序并选出max

索引截取数组元素

any()和all()实现

最后更新于

这有帮助吗?