fork download
  1. from numpy import prod
  2. the_list = [[111, 182], [264,4, 271], [48, 98, 104, 134, 141, 143, 180, 213, 225, 244, 278]]
  3. prod_lengths = prod(list(map(len, the_list)))
  4. result = list(zip(*(x*(prod_lengths//len(x)) for x in the_list)))
  5.  
  6. def get_combination(*args):
  7. for i in range(prod(list(map(len, the_list)))):
  8. yield tuple(lst[i%len(lst)] for lst in args)
  9.  
  10. result2 = list(get_combination(*the_list))
  11.  
  12. from itertools import product
  13. resultX = list(product(*the_list))
  14.  
  15. assert result == result2
  16. assert sorted(resultX) == sorted(result)
  17. assert sorted(resultX) == sorted(result2)
  18.  
  19. print("Lengths:", len(result), len(result2), len(resultX))
  20.  
  21. #for i in range(1, len(result)):
  22. # print((result[i][0]!=result[i-1][0])+(result[i][1]!=result[i-1][1])+(result[i][2]!=result[i-1][2]), result[i])
Success #stdin #stdout 0.2s 27292KB
stdin
Standard input is empty
stdout
Lengths: 66 66 66