我需要从一个csv文件打印出一个排名列表。我可以把它打印出来,这不是问题,但它看起来是这样的:
[['team1', '100'], ['team2', '200'], ['team3', '300']]
我希望它像这样打印出来:
team1, 100
team2, 200
team3, 300
我发现我对Python/英语的知识还不足以理解这里其他主题的解释,所以我不得不要求你尽可能简单 这是我正在使用的一段代码
def read():
a = open('casus.csv','r')
Areader = csv.reader(a)
a = []
for row in Areader:
if len (row) != 0:
a = a + [row]
print(a)
它不是很优雅,但您可以轻松地遍历列表:
列完单子再加上就行了。尽管更好的方法是在阅读时打印出来,或者使用字典。你知道吗
如果每个列表中正好有两个元素,则应该可以这样做。你知道吗
相关问题 更多 >
编程相关推荐