"""
Learning Goals:
 - Identify core parts of graphs, including nodes, edges, neighbors, weights, and directions.
 - Use graphs implemented as dictionaries when reading and writing simple algorithms in code
"""
g1 = {
      "A" : [ "B", "G" ],
      "B" : [ "A", "C" ],
      "C" : [ "B", "H" ],
      "D" : [ "F" ],
      "E" : [ "G", "H" ],
      "F" : [ "D" ],
      "G" : [ "A", "E", "H" ],
      "H" : [ "C", "E", "G" ]
     }

g1Weighted = {
      "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)

printNodes(g1)

###

def printEdges(g):
    seen = [ ]
    for node in g:
        for neighbor in g[node]:
            if (neighbor + "-" + node) not in seen:
                print(node + "-" + neighbor)
                seen.append(node + "-" + neighbor)

printEdges(g1)

###

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

print(getNeighbors(g1Weighted, "E"))

###

def getEdgeWeight(g, node1, node2):
    for neighbor in g[node1]:
        neighborValue = neighbor[0]
        if neighborValue == node2:
            return neighbor[1]
    return None

print(getEdgeWeight(g1Weighted, "C", "H"))

###

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

def findMostPopular(g):
    currentBest = None
    currentCount = 0
    for person in g:
        if len(g[person]) > currentCount:
            currentBest = person
            currentCount = len(g[person])
    return currentBest

print(findMostPopular(gotGraph))

###

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

print(makeInvite(gotGraph, "Arya"))
