3 ms·
Some languages use `enumerate` for this. Maps, filters, for loops etc all work on single items, but enumerate wraps them into (index, item) tuples when needed.
by DougBTX 4y ago
Some languages use `enumerate` for this. Maps, filters, for loops etc all work on single items, but enumerate wraps them into (index, item) tuples when needed.
https://docs.python.org/3/library/functions.html#enumerate https://docs.python.org/3/library/functions.html#enumerate
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.enumerate https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...
https://docs.julialang.org/en/v1/base/iterators/#Base.Iterators.enumerate https://docs.julialang.org/en/v1/base/iterators/#Base.Iterat...
Amusingly in Haskell it only takes nine characters to define enumerate, so there’s not much benefit giving it a name!
enumerate = zip [0..]
https://stackoverflow.com/a/6473153/119271 https://stackoverflow.com/a/6473153/119271