[Tutor] Create a table by writing to a text file.

Peter Otten __peter__ at web.de
Wed Feb 22 15:51:27 CET 2012


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.



More information about the Tutor mailing list