Advertisement

Python基础:itertools模块中常用的函数

阅读量:

常见函数及其功能说明

compress(data, selectors) #compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
chain(*iterables) # chain('ABC', 'DEF') --> A B C D E F
filterfalse(predicate, iterable) # filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8
accumulate(iterable[, func]) #accumulate([1,2,3,4,5]) --> 1 3 6 10 15

permutations(iterable, r=None) | # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC

排列生成与输出示例

| combinations(iterable, r)| # combinations('ABCD', 2) --> AB AC AD BC BD CD

combinations(range(4), 3) --> 012 013 023 123 |

| product(*iterables, r

全部评论 (0)

还没有任何评论哟~