以下代码足够简单明了,编译时会产生错误:
import string
import collections
#create dictionary with alphabets as keys, and empty values
list = ['aema', 'airplane', 'amend']
gen_dict = dict.fromkeys(string.ascii_lowercase, '')
gen_dict = collections.defaultdict(list)
for x in list:
gen_dict['a'].append(x)
产生的错误是:
Traceback (most recent call last):
File "indexdict.py", line 14, in <module>
gen_dict = collections.defaultdict(list)
TypeError: first argument must be callable
任何的想法?提前致谢