This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digits2alpha = {'1':('1'), | |
'2':('a','b','c'), | |
'3':('d','e','f'), | |
'4':('g','h','i'), | |
'5':('j','k','l'), | |
'6':('m','n','o'), | |
'7':('p','q','r','s'), | |
'8':('t','u','v'), | |
'9':('w','x','y','z'), | |
'0':('0')} | |
def strings(digitstring): | |
if len(digitstring) < 2: | |
return digits2alpha[digitstring[0]]; | |
else: | |
suffixes = strings(digitstring[1:]) | |
vals = [] | |
for prefix in digits2alpha[digitstring[0]]: | |
for suffix in suffixes: | |
vals.append(prefix+suffix) | |
return vals | |
if __name__ == "__main__": | |
z = strings('123') | |
print "Z is ", z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment