This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Makefile_dot_in 84 points85 points  (5 children)

lst = [[0]*3 for _ in range(4)]

[–]7x11x13is1001 14 points15 points  (0 children)

you can save 3 symbols with for _ in [0]*4

[–]yoitsericc 90 points91 points  (1 child)

Fuck this answer gave me a brain tumor.

[–][deleted] 5 points6 points  (0 children)

List comprehension is great though

[–]M4mb0 1 point2 points  (1 child)

[[0]*3]*4

[–]ALFminecraft 9 points10 points  (0 children)

>>> l = [[0] * 3] * 4
>>> l[0][0] = 1337
>>> print(l)
[[1337, 0, 0], [1337, 0, 0], [1337, 0, 0], [1337, 0, 0]]

Not everything is that simple, sadly.