我正在嘗試編寫一個函數,該函數接受例如[1,2,3]的輸入並返回[ 1,1,2,2,3,3]但我得到一個錯誤編寫一個函數,它將一個列表作爲參數,並返回一個列表,該列表重複列表中的元素
這裏是代碼我現在
def problem3(aList):
list1= []
newList1= []
for i in range (len(aList)):
list1.append(aList[i])
for i in range (0, len(list1)):
newList1= aList + list1[i]
這是錯誤
"Traceback (most recent call last): Python Shell, prompt 2, line 1 File "h:\TowlertonEvanDA7.py", line 34, in newList1= aList + list1[i] builtins.TypeError: can only concatenate list (not "int") to list"