# Comparing/Referencing Lists

Sorry everyone

I have worked this out. The more obvious the solution the harder it is for me to find.

Sorry

Hi
I am a little stuck on a python problem that must have an easy answer and I was hoping one of the Gurus could point me in the right direction as I am no python expert.

I have two lists to compare/reference??
code below

import time
cont=GameLogic.getCurrentController()
own=cont.getOwner()
from time import localtime
time=localtime()
year=time[0]
print year
month=time[1]
monthname=[“January”, “February”, “March”, “April”, “May”, “June”,
“July”, “August”, “September”, “October”, “November”, “December”,]
print monthname

month is a integer list 1-12 and monthname is a list of 12 strings(obviously).
You should be able to see where I am going with this. Is there an easy way to reference? these lists together so I dont have to do…
if month[0]==1:
displaymonth=monthname[0]
etc twelve times
I have had a good look in the python docs but I’m not even sure what I am looking for.
Dr S
PS I have posted this in the python forum as well as the Game Engine

There are lots of ways to do it, and part of the fun of python is experimenting. One way is to combine the lists by using a dictionary. It’s a keyword list:
monthDict = {1:“january”,2:“february”}
print monthDict[1]

If you want to use 2 lists, make sure they have the same length and find the position of one and then get the position of the other.

``````
n = 0
month = 5
for number in monthNumberList:
if number == month:
print  monthNameList[n]
n++

``````

Of course, you could just look at them and see the mathmatical similarities:
print monthNameList[month - 1]
You don’t really need a month number list at all because it’s a mathmatic progression.

displaymonth = monthname[month]

or somthing like that