Skip to content

Instantly share code, notes, and snippets.

@arsatiki
Created February 7, 2022 06:23
Show Gist options
  • Save arsatiki/7e2af00eb2aa42a87be560806f50ac61 to your computer and use it in GitHub Desktop.
Save arsatiki/7e2af00eb2aa42a87be560806f50ac61 to your computer and use it in GitHub Desktop.
# well'd do nested arrays, N rows inside an N-sized column (or vice versa)
# Then you can refer to a single spin with lattice[x][y]
# One approach, most obvious
N = 10
lattice = []
for x in range(N):
lattice.append([])
for y in range(N):
lattice.append('DOWN')
# But we have some tricks up our sleeve, such as the list multiplication
N = 10
lattice = []
for x in range(N):
lattice.append(['DOWN'] * N)
# And the list comprehensions which are just for loops for making lists
N = 10
lattice = [['DOWN'] * N for _ in range(N)]
# We can't do this!
N = 10
lattice = [['DOWN'] * N] * N
# because it would in fact create just one row and multiply that object
# and modifying one row would modify all of them...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment