We could also try to do this in reverse, mapping the number of days to a month name.
This first line will make an empty dictionary, which we will add to.
month_with = {}
month_with[31] = 'Jan'
month_with[28] = 'Feb'
month_with[31] = 'Mar'
month_with[30] = 'Apr'
month_with # see what we have so far
What seems to be a problem here? Can you explain it?
If you have any doubts please comment below. Please give upvote if you like this.
EXPLANATION :
Here the problem is, the dictionary must contain unique keys but here the dictionary month_with contain duplicate keys. Its shows an error.
Here keys = 31 ,28 ,31, 30 .... These elements having duplicates. If try to do this in reverse, mapping the number of days to a month name. Then it ok.
Values in a dictionary can be of any datatype and can be duplicated, whereas keys can’t be repeated and must be immutable.
Note - Keys in a dictionary doesn’t allows Polymorphism.
We could also try to do this in reverse, mapping the number of days to a...