def temperature(weather):
'''(list of ints) -> list of strs
Modify and return list, replacing each temp in list for weather condition.
Hot being over 25 degrees, and cool being under.
'''
所以,如果我运行温度([24, 29, 11]),我希望它返回 ['cool', 'hot', 'cool']。
这就是我得到的。我想我正在创建一个新列表而不是修改它。我将如何修改列表而不是使用 for 循环创建新列表?
temp =[]
for degrees in weather:
if degrees > 25:
temp = temp + ['hot']
else:
temp = temp + ['cool']
return temp