30秒到达战场
>>> lst = list(range(165))>>> lst[0::10][0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]请注意,这比循环并检查每个元素的模量快约100倍:$ python -m timeit -s "lst = list(range(1000))" "lst1 = [x for x in lst if x % 10 == 0]"1000 loops, best of 3: 525 usec per loop$ python -m timeit -s "lst = list(range(1000))" "lst1 = lst[0::10]"100000 loops, best of 3: 4.02 usec per loop