我正在尝试导入在单词游戏中使用的单词词典。我导入的文件是.rtf文件,每行有一个单词。我想将每一行变成一个大单列表的元素。该文件的名称是“TextTwistDictionary.rtf”。我该怎么做呢?
答案 0 :(得分:0)
list_words = []
with open('TextTwistDictionary.rtf') as f:
for line in f: # read every line in the file
list_words.append(line) # append each line to the list
print list_words
答案 1 :(得分:0)
with open(fileName) as fileHandle:
dictionary = fileHandle.readlines()