Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You shouldn't be using double-underscore double-underscore variables. If you want to suggest that an instance variable is private, use a name with a single underscore.

You shouldn't be using double-underscore variables. If you want to suggest that an instance variable is private, use a name with a single underscore.

You shouldn't be using double-underscore variables. If you want to suggest that an instance variable is private, use a name with a single underscore.

Fixed index-vs-content confusion pointed out by @Josay
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 479
def __str__(self):
 return "\n".join(
 [''.join(
 ['#' if row[col]cell else '.' for colcell in row]
 ) for row in self._board]
 ) + "\n"
def __str__(self):
 return "\n".join(
 [''.join(
 ['#' if row[col] else '.' for col in row]
 ) for row in self._board]
 ) + "\n"
def __str__(self):
 return "\n".join(
 [''.join(
 ['#' if cell else '.' for cell in row]
 ) for row in self._board]
 ) + "\n"
Another iteration example
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 479
board = Board.load('boardFile.dat')
# or...
# board = Board(15)
# board.fill(row=7, col=7)
game = GameOfLifeGenerator(board)
for _ in range(11):
 print(board)
 board = game.next()

Alternatively,

from itertools import islice
board = Board(15)
board.fill(row=7, col=7)
for state in islice(GameOfLifeGenerator(board), 11):
 print(state)
board = Board.load('boardFile.dat')
# or...
# board = Board(15)
# board.fill(row=7, col=7)
game = GameOfLifeGenerator(board)
for _ in range(11):
 print(board)
 board = game.next()
board = Board.load('boardFile.dat')
game = GameOfLifeGenerator(board)
for _ in range(11):
 print(board)
 board = game.next()

Alternatively,

from itertools import islice
board = Board(15)
board.fill(row=7, col=7)
for state in islice(GameOfLifeGenerator(board), 11):
 print(state)
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 479
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /