python dictionary of lists append

Do you want to know the information regarding “python dictionary of lists append”. If yes, you’re in the correct post.

python dictionary of lists append

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

Final Words

I hope this tutorial helps you to know about “python dictionary of lists append”. If you have any queries regarding this article please let us know via the comment section. Share this tutorial with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment