高效率的列表推导式:
一个普通的代码段
dtList = list(range(100000)) for i in dtList: dtList[i] = dtList[i] * dtList[i]
大家可以自己看下运行效率,大概是40毫秒
经过使用列表推导式:
dtList = [i*i for i in range(100000)]
用时约7毫秒。
上一篇:python中集合与列表怎么相互转换
下一篇:如何使用python中的decimal模块