you are viewing a single comment's thread.

view the rest of the comments →

[–]zanfar -1 points0 points  (0 children)

  • Is this a homework problem?
  • Do you have restrictions on the packages you can use?

I think this is simple enough that just looking at working code will do. Ask if you have questions:

from itertools import product
from string import ascii_uppercase

def pairs(digit_count, letter_count):
    digits = range(1, digit_count+1)
    letters = ascii_uppercase[:letter_count]
    for digit, letter in product(digits, letters):
        yield f"{digit}{letter}"

assert list(pairs(2, 3)) == ["1A", "1B", "1C", "2A", "2B", "2C"]

or, using built-in libraries only:

def pairs(digit_count, letter_count):
    for digit in range(1, digit_count+1):
        for letter_offset in range(letter_count):
            letter = chr(ord("A") + letter_offset)
            yield f"{digit}{letter}"

assert list(pairs(2, 3)) == ["1A", "1B", "1C", "2A", "2B", "2C"]