1

I've started off with this.

def month(n): lst = ['Months','Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] lst.index(x) 

I need it to work as follows:

 >>>first = month(1) >>>first 'Jan' >>> second = month(11) >>> second 'Nov' 

How can this be done?

2
  • 2
    1. start with the most basic tutorial. 2. it's done. Commented Jan 26, 2011 at 23:42
  • I still couldn't help pouncing on this one :P Commented Jan 26, 2011 at 23:43

2 Answers 2

4
def month(n): lst = ['Months','Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] return lst[n] 
Sign up to request clarification or add additional context in comments.

Comments

0

Why not use a dictionary?

lst = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] months = dict(zip(range(1, 13), lst)) month = months.get month(1) # Jan 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.