我知道在《罗密欧与朱丽叶》这出戏里有五行,其中一行既有“朱丽叶”又有“罗密欧”。我想把《罗密欧与朱丽叶》中的台词印出来,剧中有“朱丽叶”和“罗密欧”两个词。你知道吗
到目前为止,我试着:
pattern = 'Romeo and Juliet'
matching_lines = [line for line in open('Romeo and Juliet.txt').readlines() if pattern in line]
print(matching_lines)
但它只打印:
['Romeo and Juliet\n']
而不是剧中既有“罗密欧”又有“朱丽叶”的台词。你知道吗
就这么简单:
您的代码查找文本
Romeo and Juliet
,但这与Juliet and Romeo
不匹配。试试if ‘Romeo’ in line and ‘Juliet’ in line
。你知道吗使用此链接下载播放文本Romeo and Juliet
输出:
相关问题 更多 >
编程相关推荐