0

I'm trying to program a way to generate all possible combinations in this format:

01-01-01-A

Now I've already looked in the itertools.permutations and combinations libs and read examples of how they worked. Though my problem is different than the other questions I've read

the first range can go from 0-38 and the next 2 ranges can go from 0-9 and the letter can go from A-C. I'm currently stuck on how I can use itertools to generate all possible combinations using this format.

What I am currently thinking is having 1 list with 4 lists inside with each of those numbers:

first_value = []
second_value = []
third_value = []
fourth_value = ["A", "B", "C"]
final_value = []
for num in range(0, 39):
    first_value.append(num)
for num in range(0, 10):
    second_value.append(num)
    third_value.append(num)
final_value.append(first_value)
final_value.append(second_value)
final_value.append(third_value)
final_value.append(fourth_value)
for value in itertools.permutations(final_value):
    print(value)

I'm not really sure how I can program this.

3
  • You need to be precise about what you mean by "combination" and "permutation", they are not the same thing, and it's not obvious which one you want. Commented Mar 30, 2017 at 1:26
  • 1
    Try to use itertools.product Commented Mar 30, 2017 at 1:30
  • @juanpa.arrivillaga Sorry, I'm looking for permutation. I just noted that I looked into each one. Commented Mar 30, 2017 at 1:38

1 Answer 1

1

You want itertools.product.

import itertools

map(lambda t: "-".join(t), 
    itertools.product(
        map(str, range(0,39)), 
        map(str, range(0,10)), 
        map(str, range(0,10)), 
        ['A', 'B', 'C'])
    )
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. This is exactly what I needed! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.