Coverage for /home/marcofavorito/workfolder/pythomata/pythomata/utils.py : 70%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""Utils module."""
3from itertools import chain, combinations
6def iter_powerset(iterable):
7 """Get the powerset of an iterable, as an iterator."""
8 s = set(iterable)
9 combs = chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))
10 return combs
13def powerset(iterable):
14 """
15 Compute the power set of an iterable object.
17 >>> sorted([sorted(s) for s in powerset([1,2,3])])
18 [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]]
19 """
20 combs = iter_powerset(iterable)
21 res = set(frozenset(x) for x in combs)
22 return res