【发布时间】:2018-10-05 14:32:00
【问题描述】:
我有一个外部 .csv 文件,我将其读入二维列表,对其进行排序,然后打印。打印时我不想要方括号,我该如何摆脱它们?
def bubbleSort(hi):
for passnum in range(len(hi)-1,0,-1):
for i in range(passnum):
if hi[i]>hi[i+1]:
temp = hi[i]
hi[i] = hi[i+1]
hi[i+1] = temp
hi =[]
with open('winners.csv', 'r') as textfile:
for row in reversed(list(csv.reader(textfile))):
#create the file into an array
hi.append(row)
#initiate the bubble sort on the array
bubbleSort(hi)
# print the top 5 winners
for i in range(5):
print(hi[i])
给出输出:
[score, name]
[score, name]
[score, name]
[score, name]
[score, name]
如果可能的话,我只想去掉括号。 所以它看起来像:
score, name
score, name
score, name
score, name
score, name
【问题讨论】:
-
" ".join(hi[i]) -
您打印列表的目的是什么?对于最终用户?然后打印列表的内容,而不是列表本身。