# Enumerate function

**URL:** <https://discourse.julialang.org/t/enumerate-function/84007>\
**Category:** New to Julia\
**Created:** [July 10, 2022, 2:06am UTC](https://discourse.julialang.org/t/enumerate-function/84007 "2022-07-10T02:06:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JosieG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josieg/32/36221_2.png) [@JosieG](https://discourse.julialang.org/u/JosieG)\
**Post date:** [July 10, 2022, 2:06am UTC](https://discourse.julialang.org/t/enumerate-function/84007/1 "2022-07-10T02:06:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 10, 2022, 4:27am UTC](https://discourse.julialang.org/t/enumerate-function/84007/2 "2022-07-10T04:27:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JosieG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josieg/32/36221_2.png) [@JosieG](https://discourse.julialang.org/u/JosieG)\
**Post date:** [July 10, 2022, 6:19pm UTC](https://discourse.julialang.org/t/enumerate-function/84007/3 "2022-07-10T18:19:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 10, 2022, 6:24pm UTC](https://discourse.julialang.org/t/enumerate-function/84007/4 "2022-07-10T18:24:54Z")

</div>

```julia
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.

---

<div class="post-metadata">

**Author:** ![JosieG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josieg/32/36221_2.png) [@JosieG](https://discourse.julialang.org/u/JosieG)\
**Post date:** [July 10, 2022, 11:34pm UTC](https://discourse.julialang.org/t/enumerate-function/84007/5 "2022-07-10T23:34:17Z")

</div>

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

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

```
