Enumerate function

Hi, I’m new to Julia. I’m given a function

for (jd, depth) in enumerate([depth_a, depth_b])
id, re = ,
for (k, v) in an
push!(id, k)
r = run(v, depth)
push!(re, r)
end
end

In this code, depth_a and depth_b are both functions which return a number. They are two different ways to calculate a depth. But I’m confused about how enumerate works here. I searched it in google and it says it’s like iterating. I don’t know how to iterate through a function.

The code does not iterate through a function, it iterates over a vector of two functions and enumerate counts the iterations. On the first loop, jd is 1 and depth is depth_a, on the second loop jd is 2 and depth is depth_b.

1 Like

I’m still confused about it. I look at re in the next trunk and there is only one matrix with depths. But where those depths come from? depth_a or depth_b?

for (jd, depth) in enumerate([depth_a, depth_b])
    id, re = [], []
    for (k, v) in an
        push!(id, k)
        r = run(v, depth)
        push!(re, r)
    end
end

We don’t know what an is that the inner loop iterates over. But id and re are redefined inside the outer loop at each iteration, and like the code stands you wouldn’t have access to them outside that scope anyway.

an is a dict{any,any}, the part of an is

"47361"  => Dict{Any, Any}("F"=>StaticArray{Tuple{2}, T, 1} where T[], "Em…
  "146001" => Dict{Any, Any}("S"=>.....