Question

We could also try to do this in reverse, mapping the number of days to a...

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?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
We could also try to do this in reverse, mapping the number of days to a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT