# Unpack unknown number of values

**URL:** <https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753>\
**Category:** New to Julia\
**Created:** [April 21, 2021, 6:59pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753 "2021-04-21T18:59:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 21, 2021, 6:59pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/1 "2021-04-21T18:59:11Z")

</div>

Is it possible to unpack an unknown number of values, something like this?

```julia
_, x, _... = [1,2,3]

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [April 21, 2021, 7:00pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/2 "2021-04-21T19:00:54Z")

</div>

```julia
julia> _, x, _... = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> x
2

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 21, 2021, 7:01pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/3 "2021-04-21T19:01:39Z")

</div>

What version is that? I’m on 1.5.4.

```julia
julia> _, x, _... = [1,2, 3]
ERROR: syntax: invalid assignment location "_..." around REPL[26]:1

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [April 21, 2021, 7:04pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/4 "2021-04-21T19:04:51Z")

</div>

I’m on v1.6.0. LHS slurping was introduced here: [https://github.com/JuliaLang/julia/pull/37410](https://github.com/JuliaLang/julia/pull/37410)

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [April 21, 2021, 7:07pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/5 "2021-04-21T19:07:22Z")

</div>

You can also leave out the remaining values, like this:

```julia
_, x = [1,2,3]

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 21, 2021, 7:16pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/6 "2021-04-21T19:16:49Z")

</div>

> [@sostock](#):
>
> You can also leave out the remaining values, like this:
> 
> ```julia
> _, x = [1,2,3]
> 
> ```

Huh, that’s not what I expected.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 21, 2021, 9:55pm UTC](https://discourse.julialang.org/t/unpack-unknown-number-of-values/59753/7 "2021-04-21T21:55:41Z")

</div>

It is strange, but what happens is that for each identifier on the right, Julia `iterate`s the object in the left side and save the value to the corresponding identifier, so:

1. You can unpack anything that answers to `iterate` (even your own types, if you define `iterate` for them).
2. The number of identifiers in the right side cannot be greater than the number of elements in the left side object.
