gpt4 book ai didi

python - 是否有包含用于 python 的许多单词数组的库?

转载 作者:行者123 更新时间:2023-12-01 22:54:45 24 4
gpt4 key购买 nike

我需要生成随机词,并想用数组来实现,例如

随机导入

wordArray = ["wordOne", "wordTwo"...]

word = wordArray[random.randint(0, len(wordArray))]

是否有包含大型 python 单词数组的任何地方,还是我必须手动执行此操作?

最佳答案

您可以使用此列表:https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt

你可以这样解析它:

def load_words():
with open('words_alpha.txt') as word_file:
valid_words = set(word_file.read().split())

return valid_words


if __name__ == '__main__':
english_words = load_words()
# demo print
print('fate' in english_words)

Source

关于python - 是否有包含用于 python 的许多单词数组的库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73533910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com