I am a beginner at programing and python.
So I was interested in finding out the difference between a defaultdict and a normal {} dict.
See for example I made a defaultdict.
import collections
d = collections.defaultdict(list)
s = [('yellow', 1), ('blue', 2), ('yellow', 1), ('blue', 4), ('red', 1)]
for k, v in s:
if v not in d[k]: # if value not in list already
d[k].append(v)
now when I return d I get something like this.
defaultdict(<class 'list'>, {'blue': [2, 4], 'red': [1], 'yellow': [1]})
So my question is 2 fold, What is the meaning of defaultdic and how is it different from normal dic. And How can I get rid of the defaultdict in front of the dictionary.. or essentially just change it to a normal dictionary.
Does it have to do with how I append the values to the dictionary.