In Python:
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
It basically takes an iterable and adds the index of each item to the item itself.
Is there an equivalent in Elixir?
So, a helpful person (OliverMT) in the Elixir IRC channel pointed me in the right direction:
iex> Enum.with_index [1,2,3]
[{1,0},{2,1},{3,2}]
Docs: Enum.with_index/1
NB: compared to the result from Python, the order of index/value is swapped.
e.g It is {value, index} and not (index, value) like in Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With