[Tutor] Re: Calendar question

Kristian Zoerhoff kristian.zoerhoff at gmail.com
Wed Apr 6 19:07:59 CEST 2005

On Apr 6, 2005 11:58 AM, John Carmona <jeannot18 at hotmail.com> wrote:
> When you say to double-up the dictionary do you mean using the following
> method:
> Dict = [{1:1,2:4,etc.},
> {3:9,4:16, etc}]

You're close, but a list of dicts is overkill here; stick to one big
dict, and leave the keys as strings, so you can just grab data from
raw_input directly, and do something like this:

Months = {'january':1, '1':1, 'february':2, '2':2, 'march':3, '3':3 .....}

Essentially double the number of keys in the dictionary. It's a bit
redundant, but you'll be able to then just grab

>>>month = raw_input("Enter a month: ")

with no string->int conversion; the dict does it all for you, just as
it does in your code now.



More information about the Tutor mailing list