Generate 9-digit keys with Python

3

I would like to generate several values following the pattern XXX-XXX-XXX where all the possibilities will be generated, for example:

1 - 000-000-000
2 - 000-000-001
3 - 000-000-002
.
.
.
x - 999-999-999
.
.
.
x - 000-000-00A
x - 000-000-00B
.
.
.
x - A8S-71J-8SH
.
.
.
x - ZZZ-ZZZ-ZZZ

What is the best way to make this code follow the proposed standard?

    
asked by anonymous 18.12.2017 / 23:04

1 answer

7

You can use the combinations method of module itertools


import itertools
import string

for row in itertools.combinations(string.digits + string.ascii_uppercase, 9):
  s = ''.join(row)
  print('{}-{}-{}'.format(s[:3], s[3:6], s[6:9]))
    
18.12.2017 / 23:38