row=int(input("Number of rows for two dimensional list please:"))
print("Enter",row,"rows as a list of int please:")
numbers = []
for i in range(row):
numbers.append(input().split())
array=[0]*row
for i in range(row):
array[i]=[numbers]
print(array)
1 2 3
4 5 6
7 8 9
[[[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]], [[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]], [[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]]]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
答案 0 :(得分:1)
尝试使用列表推导,并使用splitlines
遍历行,然后拆分行,然后将值转换为整数:
row=input("Number of rows for two dimensional list please:")
print([list(map(int,i.split())) for i in row.splitlines()])