David Craig wrote: > distance = [[]]*len(stations) That doesn't do what you think it does: >>> a = [[]] * 3 >>> a [[], [], []] >>> a[0].append(42) >>> a [[42], [42], [42]] See? You get a list that contains the same list len(stations) times. Use [[] for _ in stations] instead.