我正在开发著名的哈姆雷特机器人程序,以使用python3.7。所以我有一个著名的莎士比亚哈姆雷特戏剧的部分脚本(以字符串输入的形式)。你知道吗
我的任务是将剧本中的句子分成几个列表,然后进一步创建句子中的单词列表。你知道吗
我正在使用从internet复制的以下代码:
''
### BEGIN SOLUTION
def hamsplits__soln0():
cleanham = ""
for char in hamlet_text:
swaplist = ["?","!", "."] #define the puntuations which we need to replace.
if char in swaplist:
cleanham += "." #replace all the puntuations with .
elif char is " ":
cleanham += char #convert all the spaces to character type.
elif char.isalpha():
cleanham += char.lower() #bringing all the letters in lower case.
hamlist = cleanham.split(". ") #spliting all the sentences as the parts of a list.
for sentence in hamlist:
hamsplits.append(sentence.split()) #spliting all the words of the sentences as the part of list.
if hamsplits[-1][-1][-1] == '.':
hamsplits[-1][-1] = hamsplits[-1][-1][:-1] # Remove trailing punctuation
''
在这里我想了解最后两行代码的含义。你知道吗
if hamsplits[-1][-1][-1] == '.':
hamsplits[-1][-1] = hamsplits[-1][-1][:-1] # Remove trailing punctuation
如果有人能帮我的话???你知道吗
假设
hamsplits
是一个3D数组。你知道吗第一行检查最后一个平面的最后一行中的最后一个元素是否为点,然后从最后一行中删除最后一个元素
应该有同样的效果
举个例子,假设我们有像这样的火腿
希望这有帮助!你知道吗
相关问题 更多 >
编程相关推荐