在Python中经常会遇到根据一定的条件筛选列表,字典,集合中的数据,常用方法为使用循环遍历,在遍历过程中根据田间判断,一列表为例,如下:
data = [1, 5, -3, -2, 8, 34]
res = []
for item in data:
if item > 0:
res.append(item)
print(res
在Python中经常会遇到根据一定的条件筛选列表,字典,集合中的数据,常用方法为使用循环遍历,在遍历过程中根据田间判断,一列表为例,如下:
data = [1, 5, -3, -2, 8, 34]
res = []
for item in data:
if item > 0:
res.append(item)
print(res