📜  附加到字典值列表 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:26.507000             🧑  作者: Mango

代码示例1
#list.append returns None, since it is an in-place operation and you are 
#assigning it back to dic[key]. So, the next time when you do 
#dic.get(key, []).append you are actually doing None.append. 
#That is why it is failing. Instead, you can simply do
dates_dict.setdefault(key, []).append(date)
#or 
from collections import defaultdict
dates_dict = defaultdict(list)
for key, date in cur:
    dates_dict[key].append(date)