Functions creating iterators for efficient looping
- In combination AB and BA is the same, deleting dublicates after sorted permutations
def tabulate(function, start=0):
"Return function(0), function(1), ..."
return map(function, count(start))Functions creating iterators for efficient looping
def tabulate(function, start=0):
"Return function(0), function(1), ..."
return map(function, count(start))accumulate([1,2,3,4,5]) --> 1 3 6 10 15
accumulate([1,2,3,4,5], initial=100) --> 100 101 103 106 110 115
accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120
chain('ABC', 'DEF') --> A B C D E F
chain.from_iterable(['ABC', 'DEF']) --> A B C D E F
# Kind of filtering
*compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
*pairwise('ABCDEFG') --> AB BC CD DE EF FG
starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000
*zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
zip('ABCD', 'xy') --> [('A', 'x'), ('B', 'y')]