Advertisement
alex0sunny

generate seqs

Jun 14th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. def recur(combs, ar):
  2.     res = []
  3.     for comb in combs:
  4.         for x in ar:
  5.             res.append(comb + [x])
  6.     return res
  7.  
  8. def gen_combs(ars):
  9.     combs = [[]]
  10.     for ar in ars:
  11.         combs = recur(combs, ar)
  12.     return combs
  13.  
  14. def no_recur(ars):
  15.     combs = [[]]
  16.     for ar in ars:
  17.         new_combs = []
  18.         for comb in combs:
  19.             for x in ar:
  20.                 new_combs.append(comb + [x])
  21.         combs = new_combs
  22.     return combs
  23.  
  24. ars = [[1, 2, 3], [10, 20], [100, 200, 300]]
  25. print(gen_combs(ars))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement