Everfighting
5/15/2017 - 3:27 PM

列表筛选

列表筛选

from random import randint
data = [randint(-10,10) for _ in range(10)]
results = filter(lambda x: x>=0, data)
from random import randint
data = [randint(-10,10) for _ in range(10)]
results = [x for x in data if x >= 0]
# 列表解析的速度更快,用timeit测试