grid = []
for i in range(height):
line = input() # width characters, each either 0 or .
row = []
for j in range(width):
row.append(line[j] == '0')
grid.append(row)
是否可以通过功能编程将其更改为一行?如果是这样,怎么样?
答案 0 :(得分:0)
你可以像@ Aran-Fey在评论中所做的那样这样做:
grid = [[char == '0' for _, char in zip(range(width), input())] for _ in range(height)]
但它没有被推荐,使你的代码更难理解。