CSCS530 Winter 2015

Complex Systems 530 - Computer Modeling of Complex Systems (Winter 2015)

View this repository on NBViewer

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
Item at agentList[2][2] is: Beast
Gaston 2 1
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
Frozen
Ann Arbor
Characters in the movie Frozen are: ['Kristoff', 'Elsa', 'Anna']
Characters in the movie Bambi are: ['Bambi']
{'Kristoff': 'Frozen', 'Mufasa': 'Lion King', 48104: 'Ann Arbor', 'Belle': 'Beauty and the Beast', 'Chip': 'Beauty and the Beast', 'Elsa': 'Frozen', 'Bambi': 'Bambi', 'Gaston': 'Beauty and the Beast', 'Simba': 'Lion King', 'Anna': 'Frozen'}