I am trying to create a function that will return the degrees of a given node in a graph. I keep running into the error unhashable type: 'list' in my degree function and I'm not really sure why this is happening since I am not trying to assign a list as a key, which is what causes this error as far as I understand. All I need to do is get the length of the values for any given key I input into degree. I feel like I'm missing something obvious but I've been staring at this long enough to lose my mind and would appreciate a fresh set of eyes.
from collections import defaultdict
graph = defaultdict(dict)
def addEdge(node1, node2): #adds edges to the graph
# create an empty list for a key node
if node1 not in graph:
graph[node1] = []
if node2 not in graph:
graph[node2] = []
graph[node1].append(node2) #adds the edges to each other
graph[node2].append(node1)
def degree(node):
for node in graph.items():
degrees = len(graph[node])
return degrees
def select():
weights = []
for i in graph:
weights.append(degree(i))