2 回答

TA貢獻1963條經(jīng)驗 獲得超6個贊
幾個問題:
您不應該
del temp_list[:]
刪除剛剛添加的對象。您的循環(huán)會更好
for
。您的變量稱為
list_of_lists
notlist_of_list
,因此list_of_list.append()
應拋出一個NameError
map
在Py3中,它會返回一個迭代器,因此您需要將其轉換為列表,可以使用,temp_list.extend(map(...))
但可以直接創(chuàng)建它。注意:的首次使用map(...)
已解壓縮到各個變量中,因此可以按預期工作。
更新的代碼:
a, b = map(int, input().split())
list_of_lists = []
for i in range(b):
temp_list = list(map(float, input().split()))
print(temp_list, i)
list_of_lists.append(temp_list)

TA貢獻1821條經(jīng)驗 獲得超5個贊
在您的代碼中,您每次都刪除臨時列表
del temp_list[:]
代替
a, b = map(int, input().split())
您可以像這樣簡單地使用它
a, b = map(int, input())
并輸入3,4之類的輸入python將自動將其作為元組獲取,并將其分別分配給變量a,b
a, b = map(int, input()) #3,4
list_of_lists = []
for i in range(b):
temp_list = list(map(float, input()))
print(temp_list, i)
list_of_lists.append(temp_list)
print (list_of_lists)
添加回答
舉報