Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A = [0, 3, 5]
- B = [5, 10, 15]
- C = product(A, B)
- for n in C:
- print(n)
- (0, 5)
- (0, 10)
- (0, 15)
- (3, 5)
- (3, 10)
- (3, 15)
- (5, 5)
- (5, 10)
- (5, 15)
- (0, 10)
- (5, 5)
- C = [p for p in product(A, B) if sum(p) == 10]
- from collections import Counter
- from itertools import chain
- Counter(chain.from_iterable(C))
- Counter({5: 2, 0: 1, 10: 1})
- for n, freq in Counter({5: 2, 0: 1, 10: 1}).items():
- print('{}: {}'.format(n, freq))
Add Comment
Please, Sign In to add comment