So I am iterating through a "list of lists" of integers in python 3.9.0 as follows:
n = 3
adjList = dict.fromkeys([i for i in range(n)], [])
p = [[1, 0], [2, 0]]
for s, e in p:
if e not in adjList[s]:
adjList[s].append(e)
I would expect adjList to result in:
{0: [], 1: [0], 2: [0]}
Instead I get:
>>> adjList
{0: [0], 1: [0], 2: [0]}
Why isn't append modifying the list specified in adjList[i] only where i is the integer key?
I can get it to work by changing adjList[s].append(e)
to adjList[s] = adjList[s] + [e]
.