In [15]:
movieList = ['Frozen','Mulan','Beauty and the Beast']
agentList = [['Elsa','Anna'],['Mulan','Shang'],['Belle','Gaston','Beast']]
# Accessing Elements of the list
print "Item at agentList[2][2] is: " + agentList[2][2]
outerList = 0
innerList = 0
findCharacter = "Gaston"
for x in agentList:
if findCharacter in x:
innerList= x.index(findCharacter)
outerList= agentList.index(x)
print agentList[outerList][innerList], outerList, innerList
In [18]:
agentDict = {'Elsa':'Frozen', 'Anna':'Frozen', 'Kristoff':'Frozen', 'Belle': 'Beauty and the Beast',
'Gaston':'Beauty and the Beast', 'Chip':'Beauty and the Beast', 48104:'Ann Arbor'}
print agentDict['Elsa']
print agentDict[48104]
movie = "Frozen"
characters = []
for key,value in agentDict.items():
if value == movie:
characters.append(key)
print "Characters in the movie " + movie + " are: " + str(characters)
# Adding elements to the dictionary
agentDict.update({'Simba':'Lion King', 'Mufasa':'Lion King', 'Bambi':'Bambi'})
movie = "Bambi"
characters = []
for key,value in agentDict.items():
if value == movie:
characters.append(key)
print "Characters in the movie " + movie + " are: " + str(characters)
#
print agentDict