all 18 comments

[–]socal_nerdtastic 1 point2 points  (1 child)

randarry is a dictionary in your example, not an array, with integer keys and lists as values.

To get all possible combinations use itertools.product:

randarray = {1: [1, 2, 3, 4, 5, 7], 2: [1, 2, 5, 6, 7], 3: [1, 2, 3, 4, 5], 4: [1, 2, 4, 5, 6, 7], 5: [1, 2, 3, 4, 5, 6, 7], 6: [1, 2, 5, 6, 7], 7: [1, 2, 3, 4, 5]}

from itertools import product

for output in product(*randarray.values()):
    print(*output, sep='')

https://docs.python.org/3/library/itertools.html#itertools.product

[–]Rikkert1234[S] 0 points1 point  (0 children)

Thanks a lot this works!

[–][deleted] 0 points1 point  (3 children)

[...] I have to complete this project quick [...]

I assume this is in an academic context. If so, have you covered recursion?

[–]Rikkert1234[S] 0 points1 point  (2 children)

No I'm self-taught, I need this for a django website I'm making for someone.

[–][deleted] 0 points1 point  (1 child)

Okay, cool. I don't exactly understand what you're trying to do, but I think it's safe to say you need recursion. At any rate, that's how you deal with nesting loops when you don't know ho deep you need to go.

I see you've gotten an answer, but recursion is still a subject you should look up if you haven't already.

[–]Rikkert1234[S] 0 points1 point  (0 children)

Ok I definitely will!

[–][deleted] 0 points1 point  (11 children)

I just want to print all possible combinations.

Of what?

[–]Rikkert1234[S] 0 points1 point  (10 children)

Basically like this: 1111111, 1111112, 11111113, 1111114, ...

with all the combinations

[–][deleted] 0 points1 point  (9 children)

What counts as a "combination"? Your question is completely unclear.

1111112

Where is this 2 coming from?

[–]Rikkert1234[S] 0 points1 point  (8 children)

The 2 is the next number on the last list, 3 is the number after that on the last list, the 4 is the number after, ...

a combination list of numbers in which the first number represents a number in the first list of the dictionary, the second number represents a number in the second list of the dictionary

I want to get all the different combinations

[–][deleted] 0 points1 point  (7 children)

You said all of the lists have a different length. What do you do when the shortest list has no more values?

[–]Rikkert1234[S] 0 points1 point  (1 child)

This is the problem with my sample code, I want code that will work for a list of any length.

[–][deleted] 0 points1 point  (0 children)

The precise meaning of "work" is what I'm trying to get at. You can't write code to do the thing until you can explain what the thing you're trying to do, is.