TypeError: first argument must be callable
问题 fs = codecs.open('grammar_new.txt', encoding='utf-8') unidata=[] d={} fr=codecs.open('rule.txt', 'w') for line in fs: line_data=line.split() for i in range(0,len(line_data)): unidata.append(line_data[i]) d = defaultdict(unidata) while executing this code will generate error as d = defaultdict(unidata) TypeError: first argument must be callable..I want to store duplicate keys in dictionary 回答1: The first argument to defaultdict must be callable . You've passed an instance of list which isn't