itertools module
In [1]:
from itertools import *
In [3]:
for value in chain('gau', 'fung'):
print value,
In [6]:
for value in combinations('gaufung', 5):
print value
In [9]:
for value in combinations_with_replacement('abc', 2):
print value
In [12]:
for value in compress('gaufung',[1,0,0,1,0,0,0]):
print value,
In [28]:
for value in dropwhile(lambda x: x>5, [7,4,6,4,1]):
print value,
Make an iterator that returns consecutive keys and groups from the iterable. The key is a function computing a key value for each element. If not specified or is None, key defaults to an identity function and returns the element unchanged. Generally, the iterable needs to already be sorted on the same key function.
In [31]:
for k, g in groupby('AAAABBBCCDAABBB'):
print k,list(g)
In [33]:
for value in product('gau','fung'):
print value
In [35]:
for value in product(range(2), repeat=3):
print value
In [39]:
for value in repeat('gau', 4):
print value,
In [41]:
for value in takewhile(lambda x: x<5, [1,4,6,4,1]):
print value,