形容词big的比较形式较大,最高级形式最大。我想打印出所有这样的三倍(早,早,早)或(硬,硬,硬),。。。你知道吗
我在用Python打开wordList.txt文件大约有5000字。我在一个小文件上完美地测试了我的代码,但是它不能在大文件上运行,因为循环太长了。你知道吗
def puzzleA(wordList):
tempList1 = []
tempList2 = []
tempList3 = []
for word in wordList:
if word[-2:]=='er':
tempList1.append(word)
if word[-3:]=='est':
tempList2.append(word)
for word1 in wordList:
for word2 in tempList1:
if word1==word2[:-2]:
tempList3.append(word1)
for word1 in tempList3:
for word2 in tempList2:
if word1==word2[:-3]:
print('{}, {}er, {}'.format(word1,word1,word2))
你们能推荐另一种算法来优化运行时间吗!你知道吗
你现在似乎在努力学习如何用一致的方式来词干。 对于您的场景,您可以使用模式替换规则列表,即“如果单词以this模式结尾,则将其替换为that”。 使用正则表达式,您可以很容易地指定模式和替换,包括“如果它以一个重复的字母结尾,则用该字母的一个实例替换它”之类的内容。你知道吗
例如:
非常感谢你发邮件给蒂埃里·拉图伊尔。我已经四个小时没看你的答案了。我不太懂你的密码。我确实像这样调整了root(word)函数:
但它现在有两个问题: 首先,单词列表中有重复的单词,所以它会产生类似[terry,terry,terrier]的内容。你知道吗
第二,很难找到这么大的三倍
我的产品[呜呜,呜呜,呜呜],[威利,威利,威利],[斯莱特,斯莱特,斯莱特],。。。你知道吗
假设不允许我先删除重复的单词。那么有没有办法访问每个键中的每个值呢。我想比较一下这些对值,以消除不需要的结果。你知道吗
蒂埃里,如果你有时间,能解释一下密码吗?你知道吗
我真的不擅长阅读清单。你知道吗
您可以构建一个
dict
,将单词的根作为键,将列表中的所有变体作为值。那么我们只保留3个值的条目。这样,我们只在列表上迭代一次,在我们创建的dict上迭代一次,使整个过程保持O(n)。你知道吗我们可以使用
defaultdict
更容易地构建dict。请注意root
函数可能需要一些改进,请查看英语形容词列表!你知道吗相关问题 更多 >
编程相关推荐