Guest User

Untitled

a guest
Sep 29th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. def product(b):
  2. result=[]
  3. for i in b[0]:
  4. if len(b)>1:
  5. xx=product(b[1:])
  6. result+=[[i]+v for v in xx]
  7. else:
  8. result+=[[i]]
  9. return result
  10. p=product([[1,2,3],[7,8],[9,4],[5,6]])
  11. print(p)
  12.  
  13. # OUTPUT
  14. # [[1, 7, 9, 5], [1, 7, 9, 6], [1, 7, 4, 5], [1, 7, 4, 6], [1, 8, 9, 5], [1, 8, 9, 6], [1, 8, 4, 5], [1, 8, 4, 6], [2, 7, 9, 5], [2, 7, 9, 6], [2, 7, 4, 5], [2, 7, 4, 6], [2, 8, 9, 5], [2, 8, 9, 6], [2, 8, 4, 5], [2, 8, 4, 6], [3, 7, 9, 5], [3, 7, 9, 6], [3, 7, 4, 5], [3, 7, 4, 6], [3, 8, 9, 5], [3, 8, 9, 6], [3, 8, 4, 5], [3, 8, 4, 6]]
Add Comment
Please, Sign In to add comment