在行迭代器上使用对
有没有更优雅的方法来做到这一点?我想用for iLine, line in lines inputFile,所以糖为pairs。但是,这似乎不适用于lines迭代器。我做错了什么,或者这根本不可能?
var iLine = 0
for line in lines inputFile:
for iCell, cell in line:
var val = false
if cell == '#':
val = true
row[iCell] = val
map[iLine] = row
iLine += 1
回答
您可以enumerate像这样使用迭代器:
import std / enumerate
for lnum, line in enumerate(lines inputFile):
# Do your thing here.
这个迭代器是在 Nim v1.4.0 中引入的,所以请确保您的版本是最新的。