Question: I want to generate sequential outcomes for a 3X5 slot machine. 
I have 5 reels of different length, e.g:

```
reel1 = [1,2,3,4,5],

reel2 = [2,3,4,5,6,7],

reel3 = [3,4,5,6,7,8,9],

reel4 = [4,5,6,7,8,9,0,1],

reel5 = [0,1,2].

```

Right now I'm using Python for loop to generate the result, but I think it may not be an effective way as in total I need 5 for loops and if the reel length is very long, then it will take quite long time to do sequential generation.

I think there may be a more effective way to do this using Python.

Anyone have any ideas?~

Answer: 
If you want random outcomes, you can use [`random.choice`](http://docs.python.org/2.7/library/random.html#random.choice):

```
from random import choice
reels = [reel1, reel2, ...]
outcome = [choice(reel) for reel in reels]

```

If you want all outcomes, use [`itertools.product`](http://docs.python.org/2/library/itertools.html#itertools.product):

```
from itertools import product
for outcome in product(*reels):
    # use outcome

```

---

With your clarification that you want sets of three numbers, I would generate the positions up-front:

```
reelpos = []
for reel in reels:
    reelpos.append(list(zip(reel, 
                            reel[1:] + reel[:1], 
                            reel[2:] + reel[:2])))

```

You can then apply `choice` or `product` to `reelpos`, which looks like:

```
[[(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 1), (5, 1, 2)],
 [(2, 3, 4), (3, 4, 5), (4, 5, 6), (5, 6, 7), (6, 7, 2), (7, 2, 3)],
 [(3, 4, 5), (4, 5, 6), (5, 6, 7), (6, 7, 8), (7, 8, 9), (8, 9, 3), 
  (9, 3, 4)],
 [(4, 5, 6), (5, 6, 7), (6, 7, 8), (7, 8, 9), (8, 9, 0), (9, 0, 1), 
  (0, 1, 4), (1, 4, 5)],
 [(0, 1, 2), (1, 2, 0), (2, 0, 1)]]

```
Not sure what you call "to generate sequential outcomes". If what you have in mind is the enumeration of all possible outcomes, keep using the five loops: there will be 5 x 6 x 7 x 8 x 3 = 5040 different combinations, not such a big number.

Even 5 reels of 20 digits would remain quite manageable using Python (3200000 combinations).