擅长:python、mysql、java
<p>没有理由使用2个for循环,因为您可以拆分该项并将其放入单个for循环中所需的格式,如下所示:</p>
<pre class="lang-py prettyprint-override"><code># Import data for CSV
csv_file = open("csv_file.txt", "r")
list_csv = [x.strip() for x in csv_file.readlines()]
dictionary_item = []
for item in list_csv:
x = item.split(",")
dictionary_item.append({'club': x[0],
'city': x[1],
'country': x[2]})
print(dictionary_item)
</code></pre>
<p>Python还有<a href="https://docs.python.org/3/library/csv.html" rel="nofollow noreferrer">a built in CSV reader</a>,如果您不想手动完成所有工作,那么最好使用它</p>