我想通過整數列表循環,例如列表= [1,-9,2,3,4,-5]並打印/回調兩個新的單獨列表如陽性項目的列表和負項另一個列表,例如[-9,-5]和[1,2,3,4]循環遍歷Python中的整數列表並返回兩個新列表
下面的代碼不能正常工作,請幫助...
def manipulate_data(list):
positives = []
negative = []
for item in list:
negative.append(item if item < 0 else positives.append(item))
print(positives)
print(negative)
錯誤是什麼? – DZDomi
暫時擱置有趣的三元運算符並使用傳統的Python語法,並且我認爲你會有更好的運氣。 – TigerhawkT3
沒有錯誤,但結果是 –