python - 如何在python中打印没有方括号的列表
问题描述
我有一个外部 .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
解决方案
如果这只是print
代码完成后的内容,您有几个选择。
lista = [1, 2, 3]
print(' '.join([str(i) for i in lista]))
print(*lista)
for i in lista:
print(i, end = ' ')
1 2 3
推荐阅读
- wordpress - Elementor 的 Wordpress 基本插件不显示样式
- sql - 在 Postgres 中从当前周获取带有时间戳的行?
- php - 从数组中取出一个字符串
- flutter - 如何使用条件语句调整图像的大小
- javascript - innerHtml 替换插入图片 Javascript
- javascript - Python 字典/json 重复键
- c++ - 我有兴趣找到带有两个键的地图的时间复杂度
- java - 将 aws gateway api 与 Lambda java 函数集成并在它们之间传递 json 数据的最简单方法是什么?
- python - Beautifulsoup 从脚本中提取数据
- python - 如何在 sklearn kmeans 中绘制成本/惯性值?