0

I have n unique lists of equal length each containing some numerical values. I have a list of n for loops that are looping over all possible combinations of values in order to do something.

for x1 in lst1:
    for x2 in lst2:
        for x3 in lst3:
            ...
               ...
                  ...
                     for xn in lstn:
                         #do something

How can I simplify this process by creating a efficient function in python?

Rebel
  • 472
  • 8
  • 25
  • What do you mean by **efficient**? – juanpa.arrivillaga Apr 26 '23 at 18:59
  • what I mean by efficient is the reduction in the run-time of the program given order O(n^n) of the existing structure. – Rebel Apr 26 '23 at 19:15
  • And thank you, that actually gives me an idea to create multiple set of variables. Let me see if that would be helpful given the specific "do something" works that needs to be done. – Rebel Apr 26 '23 at 19:16
  • But your code here simply iterates over the cartesian product of these lists. There is no more efficient way to do that. Now, whatever it is you are *actually* trying to accomplish might be better accomplished using *another approach*, but we don't actually know what you are trying to do here – juanpa.arrivillaga Apr 27 '23 at 22:11

0 Answers0