# Zip and namedtuple

**URL:** <https://discourse.julialang.org/t/zip-and-namedtuple/39516>\
**Category:** General Usage\
**Created:** [May 15, 2020, 10:42am UTC](https://discourse.julialang.org/t/zip-and-namedtuple/39516 "2020-05-15T10:42:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [May 15, 2020, 10:42am UTC](https://discourse.julialang.org/t/zip-and-namedtuple/39516/1 "2020-05-15T10:42:51Z")

</div>

Hi all,

I wonder why zip of named tuples does not take into the account names of variables. Is this a desired behavior? Is there an alternative I am not aware of, which does?

```julia
julia> x, y = (a = 1, b = 2), (b = 4, a = 3);
julia> map(i -> i[1] + i[2], zip(x,y))
2-element Array{Int64,1}:
 5
 5

```

but

```julia
julia> x, y = (a = 1, b = 2), (a = 3, b = 4);

julia> map(i -> i[1] + i[2], zip(x,y))
2-element Array{Int64,1}:
 4
 6

```

i.e order matters but not names.  
Thanks for explanation in advance.  
Tomas

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 15, 2020, 10:46am UTC](https://discourse.julialang.org/t/zip-and-namedtuple/39516/2 "2020-05-15T10:46:39Z")

</div>

NamedTuples are tuples and iterate by value.

```julia
julia> x = (a = 1, b = 2)
(a = 1, b = 2)

julia> collect(x)
2-element Array{Int64,1}:
 1
 2

```

You can use `pairs` to iterate by `Symbol => value`:

```julia
julia> collect(pairs(x))
2-element Array{Pair{Symbol,Int64},1}:
 :a => 1
 :b => 2

```

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [May 15, 2020, 4:57pm UTC](https://discourse.julialang.org/t/zip-and-namedtuple/39516/3 "2020-05-15T16:57:32Z")

</div>

Thanks Kristoffer for answer.

That means you suggest this?

```julia
julia> collect(zip(pairs(x), pairs(y)))
2-element Array{Tuple{Pair{Symbol,Int64},Pair{Symbol,Int64}},1}:
 (:a => 1, :a => 3)
 (:b => 2, :b => 4)

```
