Source

wd_pys60 / wd_key_mapping.py

shengMu=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','zh','ch','sh']
yunMu= ['a','o','e','i','u','ai','ei','ui','ao','ou','iu','ie','ve','er','an','en','in','un','vn','ang','eng','ing','ong']
from pinyin import pinYin
import random
keyDic={"2":"abc","3":"def","4":"ghi","5":"jkl","6":"mno","7":"pqrs","8":"tuv","9":"wxyz"}
#for (key,value) in keyDic.items():
    #print key,value
running=1
while running:
    inputKey=list(raw_input(":"))
    if inputKey==["0"]:
        running=0
        break
    #inputKey=list("943")
    #print keyDic["2"]
    tempList=[]
    word=[]
    output=[]
    for key in inputKey:
        tempList.append(list(keyDic[key]))
    pinYinNum=1
    for key in inputKey:
        pinYinNum*=len(keyDic[key])

    while 1:
        word=[]
        for j in range(len(inputKey)):
            try:
                w=random.choice(tempList[j])
                word.append(w)
                #tempList[j].remove(w)
            except:
                pass
        word="".join(word)
        if word not in output:
            output.append(word)
        word=[]
        if len(output)==pinYinNum:
            break
    print [word for word in output if word  in pinYin]