擅长:python、mysql、java
<p>我认为你必须这样做:</p>
<pre><code>dictionary = {}
file = open("text_file.txt", "r")
colors = ("Bright red", "Light green", "Sky blue", "Dark brown")
for line in file:
if line[0:-1] in colors:
dictionary[line] = ""
file.close()
</code></pre>
<p>文件中的行是<code>'line\n'</code>。你知道吗</p>
<pre><code>'line\n' != 'line'
</code></pre>