As you may have understood with the title, I need some smart thinking here 🙂
I have a List<List<Object>> object. If you think of the Object objects as integers, you could see it like this :
{{1,2},{10,20,30},{100}}
I need to get all possible lists containing exactly one element of each list, that is, come up with this :
{{1,10,100},{1,20,100},{1,30,100},{2,10,100},{2,20,100},{2,30,100}}
Of course you don’t know at compiling time how much items the lists will contain, so you cannot rely on an overlapping of for loops…
How would you come up with this? Time constraints are not relevant to my problem because the lists will likely contain few elements.
I won’t implement it, but here’s an idea for a recursive algorithm:
{{1,2,3}}), then the result is – of course – a list of lists containing one element each (i.e.e.g.{{1},{2},{3}}Here’s raw Python code: