我将如何在列表理解中编写以下代码?
grid = open('some_file.txt', 'r')
lines = [line.strip('\n') for line in grid]
list_of_lists = []
for line in lines:
elms = [int(elm) for elm in line.split(' ')]
list_of_lists.append(elms)
我的文件如下所示:
3 8 6 9 4
4 3 0 8 6
2 8 3 6 9
3 7 9 0 3
意思就是:
grid = '3 8 6 9 4\n4 3 0 8 6\n2 8 3 6 9\n3 7 9 0 3'
PIPIONE
米脂
相关分类