2014-04-03 49 views

回答

0

我要去推断和猜测,你正在寻找一个Counter

>>> from collections import Counter 
>>> x = ["one", "two", "three" ] 
>>> Counter(x) 
Counter({'three': 1, 'two': 1, 'one': 1}) 
1
print dict.fromkeys(["one","two","three"],1) 

是我会怎么做?如果你真的只想做一个字典从列表(可能加速搜索)

,如果你不关心的值是你可以做

print dict.fromkeys(["one","two","three"]) 
01什么

,这将是默认None

这对蟒蛇< 2.7工作的好处,再加上它很容易告诉你在做什么,那里的字典推导总让我想起一套内涵的