Guest User

Untitled

a guest
Oct 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. A = [0, 3, 5]
  2. B = [5, 10, 15]
  3. C = product(A, B)
  4.  
  5. for n in C:
  6. print(n)
  7.  
  8. (0, 5)
  9. (0, 10)
  10. (0, 15)
  11. (3, 5)
  12. (3, 10)
  13. (3, 15)
  14. (5, 5)
  15. (5, 10)
  16. (5, 15)
  17.  
  18. (0, 10)
  19. (5, 5)
  20.  
  21. C = [p for p in product(A, B) if sum(p) == 10]
  22.  
  23. from collections import Counter
  24. from itertools import chain
  25. Counter(chain.from_iterable(C))
  26.  
  27. Counter({5: 2, 0: 1, 10: 1})
  28.  
  29. for n, freq in Counter({5: 2, 0: 1, 10: 1}).items():
  30. print('{}: {}'.format(n, freq))
Add Comment
Please, Sign In to add comment