Having an alphabet of letters A-Z and numbers 0-9, how to get all 1296 possible combinations like:
['AA', 'AB', ..., 'AZ', 'A0', 'A1', ..., 'Z9', '0A', '0B', ..., '98', '99']
As a side question, what is this type of number system called?
Having an alphabet of letters A-Z and numbers 0-9, how to get all 1296 possible combinations like:
['AA', 'AB', ..., 'AZ', 'A0', 'A1', ..., 'Z9', '0A', '0B', ..., '98', '99']
As a side question, what is this type of number system called?
Current suggestions are wrong. Combinations with replacement, for example, won't give you AB
and BA
at the same time, only the first one. And permutations
won't have AA
, BB
, etc.
Instead you should use itertools.product
.
For example:
import string
import itertools
combinations_generator = itertools.product(string.ascii_uppercase + string.digits,
repeat=2)
combinations = list(map(''.join, combinations_generator))
print(len(combinations))
This will give you exactly 1296 combinations.
combinations_generator
will generate tuples like ('A', 'A')
, ('A', 'B')
, etc.
And with map(''.join, combinations_generator)
we will join them together like 'AA'
, 'AB'
, etc.
you can use permutations to get the list.
For example
import string
import itertools
series = [''.join(r) for r in itertools.permutations([str(i) for i in range(10)]+[str(c) for c in string.ascii_uppercase], 2)]
print(series)
print(len(series)) # got 1260 here