# Array/vector comprehension and AbstractTrees Leaves iterator

**URL:** <https://discourse.julialang.org/t/array-vector-comprehension-and-abstracttrees-leaves-iterator/102337>\
**Category:** General Usage\
**Tags:** iterators, comprehension\
**Created:** [August 1, 2023, 1:18am UTC](https://discourse.julialang.org/t/array-vector-comprehension-and-abstracttrees-leaves-iterator/102337 "2023-08-01T01:18:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [August 1, 2023, 1:18am UTC](https://discourse.julialang.org/t/array-vector-comprehension-and-abstracttrees-leaves-iterator/102337/1 "2023-08-01T01:18:45Z")

</div>

Why the array comprehension behaves differently with the `AbstractTrees.Leaves` iterator?  
In the following replacing `Leaves(t)` with say, `range(1,3,3)`, I do get the 2D array.

```julia-repl
julia> using AbstractTrees

julia> t = [[1, 2], 3]
2-element Vector{Any}:
  [1, 2]
 3

julia> [(i,j) for i in Leaves(t), j in Leaves(t)]
9-element Vector{Tuple{Int64, Int64}}:
 (1, 1)
 (2, 1)
 (3, 1)
 (1, 2)
 (2, 2)
 (3, 2)
 (1, 3)
 (2, 3)
 (3, 3)

julia> [(i,j) for i in collect(Leaves(t)), j in collect(Leaves(t))]
3×3 Matrix{Tuple{Int64, Int64}}:
 (1, 1) (1, 2) (1, 3)
 (2, 1) (2, 2) (2, 3)
 (3, 1) (3, 2) (3, 3)

```
