跳转到主要内容

在迭代器上进行操作的更多常规操作,超出itertools

项目描述

https://readthedocs.org/projects/more-itertools/badge/?version=latest

Python的itertools库是一颗宝石 - 您可以使用它提供的函数为各种问题编写优雅的解决方案。在more-itertools中,我们收集了处理Python迭代器的额外构建块、食谱和常规操作。

分组

chunkedichunkedchunked_evenslicedconstrained_batchesdistributedividesplit_atsplit_beforesplit_aftersplit_intosplit_whenbucketunzipbatchedgrouperpartitiontranspose

前瞻和回顾

spypeekableseekable

窗口化

windowedsubstringssubstrings_indexesstaggerwindowed_completepairwisetriplewisesliding_windowsubslices

增强

count_cycleinterspersepaddedrepeat_eachmark_endsrepeat_lastadjacentgroupby_transformpad_nonencycles

组合

collapsesort_togetherinterleaveinterleave_longestinterleave_evenlyzip_offsetzip_equalzip_broadcastflattenroundrobinprependvalue_chainpartial_product

总结

ilenunique_to_eachsampleconsecutive_groupsrun_lengthmap_reducejoin_mappingsexactly_nis_sortedall_equalall_uniqueminmaxfirst_truequantifyiequals

选择

islice_extendedfirstlastoneonlystrictly_nstriplstriprstripfilter_exceptmap_exceptfilter_mapiter_suppressnth_or_lastunique_in_windowbefore_and_afternthtaketailunique_everseenunique_justseenuniqueduplicates_everseenduplicates_justseenclassify_uniquelongest_common_prefixtakewhile_inclusive

数学

dftidftconvolvedotproductfactormatmulpolynomial_from_rootspolynomial_derivativepolynomial_evalsievesum_of_squarestotient

组合学

distinct_permutations(不同排列),distinct_combinations(不同组合),circular_shifts(循环移位),partitions(划分),set_partitions(集合划分),product_index(乘积索引),combination_index(组合索引),permutation_index(排列索引),combination_with_replacement_index(有重复的组合索引),gray_product(格雷码乘积),outer_product(外积),powerset(幂集),powerset_of_sets(集合的幂集),random_product(随机乘积),random_permutation(随机排列),random_combination(随机组合),random_combination_with_replacement(带重复的随机组合),nth_product(第n个乘积),nth_permutation(第n个排列),nth_combination(第n个组合),nth_combination_with_replacement(带重复的第n个组合)

包装器

always_iterablealways_reversiblecountableconsumerwith_iteriter_except

其他

locaterlocatereplacenumeric_rangeside_effectiteratedifferencemake_decoratorSequenceViewtime_limitedmap_ifiter_indexconsumetabulaterepeatfuncreshapedoublestarmap

入门指南

要开始使用,请使用 pip 安装库

pip install more-itertools

itertools 文档中的菜谱包含在顶层包中

>>> from more_itertools import flatten
>>> iterable = [(0, 1), (2, 3)]
>>> list(flatten(iterable))
[0, 1, 2, 3]

还有几个新的菜谱可用

>>> from more_itertools import chunked
>>> iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8]
>>> list(chunked(iterable, 3))
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]

>>> from more_itertools import spy
>>> iterable = (x * x for x in range(1, 6))
>>> head, iterable = spy(iterable, n=3)
>>> list(head)
[1, 4, 9]
>>> list(iterable)
[1, 4, 9, 16, 25]

有关函数的完整列表,请参阅 API 文档

开发

more-itertools@erikrose@bbayles 维护,并得到了许多其他人的帮助。如果您有问题或建议,请在此仓库中提交错误报告或拉取请求。感谢您的贡献!

版本历史

版本历史可以在 文档 中找到。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源代码发行版

more-itertools-10.5.0.tar.gz (121.0 kB 查看散列)

上传时间 源代码

构建发行版

more_itertools-10.5.0-py3-none-any.whl (61.0 kB 查看散列)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面