擅长:python、mysql、java
<p>首先,你应该把它存储为一个列表(或者列表列表),而不是把它变成一个字典。你知道吗</p>
<pre><code>d=[]
while True:
try:
#filename=input("Enter the name of the file to open: ") + ".txt"
with open("file.txt","r") as f:
for line in f:
splitLine=line.split()
d.extend(splitLine)
#print(line, end="")
break
except FileNotFoundError:
print("File name does not exist; please try again")
for elem in d:
print elem
</code></pre>
<p>如果您使用这样的列表结构,然后最后使用循环遍历所有元素,您将获得所需的输出。你知道吗</p>
<p>输出:</p>
<pre><code>ABC
CAB
BCA
</code></pre>