<分区>
所以我想确定给定字符串中的单词。这些字符串是域名。我有大约 5000 个域名和 60000 个字典单词的字典要检查。这将导致每个域检查 60000 次,总计大约 300.000.000 次操作,这简直是疯狂。
因此我想问一下,是否有更聪明的方法来解决这个问题,让字符串中的单词仍然存在。
我尝试用一个简单的循环来完成它,但我想这需要一个更智能的解决方案来处理大量的支票。
dictionary_of_words = ["I", "Stack", "overflow", "like", etc]
AllDomains = ["stackoverflow.com", "iLikeStackoverflow.com", etc]
def in_dictionary(AllDomains):
#Setting a new column
AllDomains["dictionary"] = False
AllDomains["words"] = None
for i in range(len(AllDomains)):
# Scan if the entire word is in the dictionary
if AllDomains["domain"].str.strip(".nl").str.lower().iloc[i] in dictionary_of_words:
AllDomains["dictionary"].iloc[i] = True
print(AllDomains["domain"].iloc[i])
# Scan which words there are in the domain
else:
for word in dictionary_of_words:
print(word)
if word in AllDomains["domain"].str.strip(".nl").str.lower().iloc[i]:
if AllDomains["words"].iloc[i] == None:
AllDomains["words"].iloc[i] = word
else:
AllDomains["words"].iloc[i] = AllDomains["words"].iloc[i] + f", {word}"
print(AllDomains["domain"].iloc[i])
return AllDomains