输入的Python ValueError异常:值过多解压(预期2)
2 4
1 2 3 4
1 0
2 1
2 3
我需要的对从第三行号提取到端(只从第三行2号)
这里是我的功能
def read_nodes():
n, r = map(int, input().split())
n_list = []
for i in range(2 , n):
n1, n2 = map(int, input().split())
n_list.append([n1, n2])
return n_list
print(read_nodes())
我除了[[1,0],[2,1],[2,3]]
但说 ValueError: too many values to unpack (expected 2)
输入是矩阵吗? –
是你的输入作为单行传递? – RomanPerekhrest
第二行输入由for循环的第一次迭代处理。你在'2'开始索引的事实并没有改变这一点。 – Kendas