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] ]
     }

###

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

###

def getNeighbors(g, node):
    neighbors = []
    for pair in g[node]:
        neighbors.append(pair[0])
    return neighbors

###

def getAllEdges(g):
    for node1 in g:
        for node2 in g[node1]:
            print(node1, "-", node2)

###

def getEdgeWeight(g, node1, node2):
    for pair in g[node1]:
        neighborValue = pair[0]
        if neighborValue == node2:
            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 mostPopularPerson(g):
    mostPopPerson = None
    mostPopCount = -1
    for person in g:
        numFriends = len(g[person])
        if numFriends > mostPopCount:
            mostPopPerson = person
            mostPopCount = numFriends
    return mostPopPerson

###

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

###

"""You do: Given an unweighted graph of a social network (like in the previous two examples)
and two nodes (people) in the graph, return a list of the friends that those two people have in common."""
def friendsInCommon(g, p1, p2):
    friends = []
    for person in g[p1]:
        if person in g[p2]:
            friends.append(person)
    
    return friends