by runevault · 4y ago · 0 comments
julia> pairs("François") |> collect
8-element Vector{Pair{Int64, Char}}:
1 => 'F'
2 => 'r'
3 => 'a'
4 => 'n'
5 => 'ç'
7 => 'o'
8 => 'i'
9 => 's'
Notice the missing index 6, because ç takes two bytes.In contrast, enumerate() gets you the iteration number:
julia> enumerate("François") |> collect
8-element Vector{Tuple{Int64, Char}}:
(1, 'F')
(2, 'r')
(3, 'a')
(4, 'n')
(5, 'ç')
(6, 'o')
(7, 'i')
(8, 's')
This can trip you up.Edit: Also thank you for the answer. I have been curious about Julia even though I'm not a data science/ML type, but never find time. I do like to keep an eye on it though.
julia> "François"[6]
ERROR: StringIndexError: invalid index [6], valid nearby indices [5]=>'ç' [7]=>'o'
I’m not a data science type either. I came to Julia through physics and general computing. It’s the best language for science I’ve ever encountered.