【发布时间】:2019-04-13 05:58:02
【问题描述】:
练习我的蟒蛇。
任务: 遍历列表 A 并创建一个新列表,其中仅包含 0-5 之间的列表 A 中的项目。
我做错了什么
a = [100, 1, 10, 2, 3, 5, 8, 13, 21, 34, 55, 98]
def new_list(x):
for item in range(len(x)):
new = []
if x[item] < 5 and x[item] > 0:
(new.append(item))
return new
print(new_list(a))
我刚刚收到[1] 作为答案。
【问题讨论】:
-
将
new = []移动到你的 for 循环之前
标签: python list for-loop append