我想从列表中调用某些单词(长度超过 11 个字符)并找出可以使用手机上的相同按键键入的单词,例如“compurgations”和“constrictions”都共享相同的代码(2667874284667 )。
我能够用笨拙但有效的编码将每个单词变成一个数字字符串。
numbers = []
dial = []
for word in lowers:
if len(word)>11 and "\'" not in word:
dial.append(word)
if len(word)>11 and "\'" not in word:
worda = word.replace('a','2')
wordb = worda.replace('b','2')
wordc = wordb.replace('c','2')
wordd = wordc.replace('d','3')
worde = wordd.replace('e','3')
wordf = worde.replace('f','3')
wordg = wordf.replace('g','4')
wordh = wordg.replace('h','4')
wordi = wordh.replace('i','4')
wordj = wordi.replace('j','5')
wordk = wordj.replace('k','5')
wordl = wordk.replace('l','5')
wordm = wordl.replace('m','6')
wordn = wordm.replace('n','6')
wordo = wordn.replace('o','6')
wordp = wordo.replace('p','7')
wordq = wordp.replace('q','7')
wordr = wordq.replace('r','7')
words = wordr.replace('s','7')
wordt = words.replace('t','8')
wordu = wordt.replace('u','8')
wordv = wordu.replace('v','8')
wordw = wordv.replace('w','9')
wordx = wordw.replace('x','9')
wordy = wordx.replace('y','9')
wordz = wordy.replace('z','9')
numbers.append(wordz)
numberset = set(numbers)
然后我打算搜索每个数字出现的次数,如果大于 1,记录位置并将其从另一个列表中拉到一起,将它们作为元组提供。我不知道如何找出与位置共享相同号码的人。