Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

append to a ldictionary value list

#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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #append #ldictionary #list
ADD COMMENT
Topic
Name
8+2 =