Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python append value to dictionary list

import collections

a_dict = collections.defaultdict(list) # a dictionary key --> list (of any stuff)
a_dict["a"].append("hello")

print(a_dict)
>>> defaultdict(<class 'list'>, {'a': ['hello']})

a_dict["a"].append("kite")

print(a_dict)
>>> defaultdict(<class 'list'>, {'a': ['hello', 'kite']})
Source by www.kite.com #
 
PREVIOUS NEXT
Tagged: #python #append #dictionary #list
ADD COMMENT
Topic
Name
3+1 =