0

Is it possible to speed up the search of all possible combinations from several arrays?

out = []
for a1 in range(1, 10000):
   for a2 in range(1, 10000):
       for a3 in range(1, 10000):
           for a4 in range(1, 10000):
               for a5 in range(1, 10000):
                   for a6 in range(1, 10000):
                       for a7 in range(1, 10000):
                           out.append([a1, a2, a3, a4, a5, a6, a7])
  • 2
    use itertools.combinations – Zaraki Kenpachi Jan 23 '20 at 12:17
  • Does this answer your question? [All combinations of a list of lists](https://stackoverflow.com/questions/798854/all-combinations-of-a-list-of-lists) – Chillie Jan 23 '20 at 12:17
  • 1
    Does this answer your question? [How to get all possible combinations of a list’s elements?](https://stackoverflow.com/questions/464864/how-to-get-all-possible-combinations-of-a-list-s-elements) – Tomerikoo Jan 23 '20 at 12:17
  • 3
    That's called the `cartesian product`. You can use [itertools.product](https://stackoverflow.com/a/533917/4110792) for that, but if you have 7 arrays of size 10^4, you don't want to have that in memory, it's better to have a generator doing the product as you go. Of course it depends on what you are doing. – MkWTF Jan 23 '20 at 12:17

0 Answers0