def combinations_with_replacement(iterable, r):
"""
>>> list(combinations_with_replacement('AT', 2))
[('A', 'A'), ('A', 'T'), ('T', 'T')]
"""
assert isinstance(r, (int, long))
assert r >= 0
if r == 0:
yield ()
else:
alls = list(iterable)
for (i, el) in enumerate(alls):
for els in combinations_with_replacement(alls[i:], r - 1):
yield (el,) + els
评论列表
文章目录