我是Python的新手,尤其是TensorFlow,并且一直在关注本教程,但是我不理解此return语句中到底发生了什么。我对“ conversation_chunks中的el的“ el [3] .strip())。split(”,“)”的功能特别困惑。完整的教程是:https://hub.packtpub.com/build-and-train-rnn-chatbot-using-tensorflow/
我不明白为什么它是“ el [3] .strip而不仅仅是el.strip?[3]与什么有关?我假设没有索引?
import re
def read_conversations(storage_path, storage_dir):
filename = storage_path + "/" + storage_dir + "/cornell movie-dialogs corpus/movie_conversations.txt"
with open(filename, "r", encoding="ISO-8859-1") as fh:
conversations_chunks = [line.split(" +++$+++ ") for line in fh]
return [re.sub('[[]']', '', el[3].strip()).split(", ") for el in conversations_chunks]
格式为:u0 +++ $ +++ u2 +++ $ +++ m0 +++ $ +++ ['L194','L195','L196','L197']。该教程说,我们正在尝试“清理方括号和撇号以获取ID的完整列表。”