python得到单词模式的示例

Python探路者 2018-10-15

如下所示:

def getWordPattern(word):
 pattern = []
 usedLetter={}
 count=0
 for i in word:
 if i not in usedLetter:
 usedLetter[i]=count
 count+=1
 pattern.append(str(usedLetter[i]))
 return '.'.join(pattern)
def main():
 print getWordPattern("hello")
if __name__=="__main__":
 main()

python得到单词模式的示例

相关推荐