Learning Nim and I like it resemblence of Python (but fast). In Python I can do this:
item_index = [(idx, itm) for idx, itm in enumerate(row)]
Im looking for a way to enumerate a Nim sequence so I would write this:
item_index = lc[(idx, itm) | (idx, itm <- enumerate(row))]
Does this functionality exist? I'm sure you could create it, maybe with a proc, template or macro it but I'm still very new, and these seem hard to create myself still. Here is my attempt:
iterator enumerate[T](s: seq[T]): (int, T) =
var i = 0
while i < len(s):
yield (i, s[i])
i += 1
pairs
on the given expression. Thepairs
operator is defined foropenarray
in system.nim and it does exactly whatenumerate
does. – Hsining