我有一个外部.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
答案 0 :(得分:0)
在代码完成后,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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] s = scanner.nextLine().split(" "); int arows = Integer.parseInt(s[0]); int acols = Integer.parseInt(s[1]); int[][] cells = new int[arows][acols]; for (int col = 0; col < acols; col++){ for (int row = 0; row <= arows;row++){ cells[row][col] = Integer.parseInt(s[2]); } } } }