unweightedGraph = { 
      "A" : [ "B", "G" ],
      "B" : [ "A", "C" ],
      "C" : [ "B", "H" ],
      "D" : [ "F" ],
      "E" : [ "G", "H" ],
      "F" : [ "D" ],
      "G" : [ "A", "E", "H" ],
      "H" : [ "C", "E", "G" ]
     }

###

weightedGraph = { 
      "A" : [ ["B", 5], ["G", 2] ],
      "B" : [ ["A", 5], ["C", 3] ],
      "C" : [ ["B", 3], ["H", 9] ],
      "D" : [ ["F", 4] ],
      "E" : [ ["G", 1], ["H", 7] ],
      "F" : [ ["D", 4] ],
      "G" : [ ["A", 2], ["E", 1], ["H", 2] ],
      "H" : [ ["C", 9], ["E", 7], ["G", 2] ]
     }

###

# nodes
def printNodes(g):
    for node in g:
        print(node)

###
        
# neighbors
def getNeighbors(g, node):
    return g[node]

###

# weighted graph
def getNeighbors(g, node):
    neighborList = []
    for pair in g[node]:
        neighborList.append(pair[0])
    return neighborList

###

# edges
def printEdges(g):
    for node in g:
        neighborList = g[node]
        for neighbor in neighborList:
            print(node, "-", neighbor)

###
            
# weights
def getWeight(g, source, destination):
    neighborList = g[source]
    for pair in neighborList:
        if pair[0] == destination:
            return pair[1]

###

g = { "Jon" : [ "Arya", "Tyrion" ],
      "Tyrion" : [ "Jaime", "Pod", "Jon" ],
      "Arya" : [ "Jon" ],
      "Jaime" : [ "Tyrion", "Brienne" ],
      "Brienne" : [ "Jaime", "Pod" ],
      "Pod" : [ "Tyrion", "Brienne", "Jaime" ],
      "Ramsay" : [ ]
    }

def findMostPopular(g):
    mostPop = None
    mostPopCount = -1
    for person in g:
        numFriends = len(g[person])
        if numFriends > mostPopCount:
            mostPop = person
            mostPopCount = numFriends
    return mostPop

###

def makeInviteList(g, person):
    inviteList = g[person] + []
    for friend in g[person]:
        for friendOfFriend in g[friend]:
            if friendOfFriend != person and \
               friendOfFriend not in inviteList:
                inviteList.append(friendOfFriend)
    return inviteList

###

def friendsInCommon(g, person1, person2):
    sharedFriends = []
    
    for friend in g[person1]:
        if friend in g[person2]:
            sharedFriends.append(friend)
    return sharedFriends