spicyjerry spicyjerry - 3 years ago 162
Python Question

All 2 character a-z & 0-9 combinations - python

How could I generate all the 2 character combinations containing a-z characters and numbers.

I believe there are 36^2 possibilities.

Thank you

Solution based on Rhosu's answer:



import string
alphanum = string.ascii_lowercase + string.digits
combination = []
for val1 in alphanum:
for val2 in alphanum:
combination.append(val1+val2)
print(combination)

Answer Source

Try

import string

alphanum = string.ascii_lowercase + string.digits

combs = [val1+val2 for val1 in alphanum for val2 in alphanum]

This should give a list of all possible 36^2 two character strings using all letters and numbers.

Edit: modified to use string.digits

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download