慕雪6442864
Python有一个用于快速基准测试的模块:timeitPython 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import timeit>>> timeit.timeit("[n for n in range(10)]")0.4846451000000229>>> timeit.timeit("list(range(10))")0.3175106840000126>>> 显然,使用速度更快。它也不那么冗长,意图更清晰恕我直言(列表推导式通常用于转换/过滤可迭代对象)。list()