标签: python dictionary
我正在使用整数作为python中的键创建一个列表字典。但是下面的代码告诉我t是None。
t = y.get("1",[]).append(1)
(但是当我做counter[c] = counter.get(c,0) + 1时,它会起作用。)
counter[c] = counter.get(c,0) + 1
有人可以帮忙吗?
答案 0 :(得分:2)
您使用None方法获取t append的原因是因为append未返回值。你可以试试这个:
None
t
append
t = y.get("1",[]) t.append(1)