Search
 
SCRIPT & CODE EXAMPLE
 

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']})
Comment

how to add element to list value in a dict python

dates_dict.setdefault(key, []).append(date)
Comment

PREVIOUS NEXT
Code Example
Python :: rotate 2 dimensional list python 
Python :: how to convert user integer input to string in python 
Python :: matplotlib set colorbar range 
Python :: python libraries 
Python :: boolean python example 
Python :: python chatbot error 
Python :: anaconda install python 
Python :: python check for exception 
Python :: numpy split 
Python :: how to read frame width of video in cv2 
Python :: delete function python 
Python :: python coin flip 
Python :: how to read a excel file in python 
Python :: takes 2 positional arguments but 3 were given 
Python :: function python 
Python :: search an array in python 
Python :: how to run a python package from command line 
Python :: python symbol 
Python :: python run uvicorn 
Python :: hide password in python 
Python :: partition python 
Python :: circular linked list in python 
Python :: python : search file for string 
Python :: python palindrome program 
Python :: how to transcode a video in python using ffmpeg 
Python :: python http post file 
Python :: addition array numpy 
Python :: remove last element in list python 
Python :: number pattern program in python using for loop 
Python :: ValueError: tuple.index(x): x not in tuple 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =