Personal Project

Hi there,

Currently working on a small personal project. I am trying to code an iteration block, which will give me all the possible outcomes from my selected inputs. The first 4 characters of the output need to be a-to-z, and the last 2 characters need to be 1-to-9. Here is what I have got so far.

url = ''
list_1 = string.ascii_lowercase
list_2 = string.ascii_lowercase
list_3 = string.ascii_lowercase
list_4 = string.ascii_lowercase
list_5 = list(range(0, 9))
list_6 = list(range(0, 9))

a = list_1, list_2, list_3, list_4, list_5, list_6

all_combos = list(itertools.permutations(a,6))


Essentially I would be looking for it to return something like: [aaaa01, aaaa02,…] and so on, all the way through to zzzz99.

I can’t seem to get it to iterate INSIDE of the lists. Instead it just iterates the lists. I was thinking that perhaps I could make a ‘for - in -’ on all of the lists to get them to iterate through, but I have no idea how to do so (im relatively new to both coding and Python).

I have looked online but none of the tutorials relate to the exact thing I am trying to do, and the documentation for itertools is hella confusing to me.

The final product should print me a load of possible URL’s that I can then click on.

I have also imported the following:

import itertools
import string
import tabulate

Any help would be massively appreciated, and if you can spare the time to explain the solution to me, that would be even better.

Cheers :slight_smile:

If you’re familiar with a different language Python’s loops are fairly easy to pick up. As for the code itself if you check the documentation you’ll find that itertools.permutations only accepts a single iterable- itertools.permutations dcoumentation. This will be why your tuple of lists only acts on each list in turn. Some itertools would allow for nested sequences *iterables but not permutations.

I’d advise you to start small since it’s hard to keep track of all the various itertools options, so maybe use some shorter lists and iterables to test if you don’t want to start with the basics. Have a very close look at each of the example outputs to see which one is closest to your desired output. If they’re close but not quite right there are recipes in the same documentation pages and you could look at the external package more-itertools for even more extended tools.

1 Like