【发布时间】:2014-02-24 23:30:29
【问题描述】:
I have the following script:
dict_class = dict()
for p in points:
dict_class[p.class] = dict_class.get(p.class, 0) + 1
print dict_class
{1: 1314, 2: 1050}
其中“points”是一个值列表。 我的问题是,是否可以转换字典的列表理解以加快我的代码速度?
【问题讨论】:
-
@Bill:还没有这个循环,因为那需要自我引用。
标签: python performance optimization dictionary list-comprehension