# Best way to convert a NTuple to a Set

**URL:** https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532
**Category:** General Usage
**Tags:** question, set, convert, ntuple
**Created:** [August 14, 2019, 1:32pm UTC](https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532 "2019-08-14T13:32:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 14, 2019, 1:32pm UTC](https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532/1 "2019-08-14T13:32:18Z")

</div>

I did:

```julia
julia> ntup = (1, 2, 3, 4, 5, 6), NTuple{6, Int}
julia> Set(ntup)
Set(Any[(1, 2, 3, 4, 5, 6), NTuple{6,Int64}])

```

But I want to get a set of Int64.  
How can I achieve that?

---

<div class="post-metadata">

### Author: ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)
#### Post date: [August 14, 2019, 1:59pm UTC](https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532/2 "2019-08-14T13:59:30Z")

</div>

Your first line isn’t doing what you probably think it’s doing. It creates a tuple of length 2 where the first item is a tuple of 6 integers and the second item is the `Type` `NTuple{6,Int}`. So of course, the `Set` constructor which simply takes an iterable constructs a `Set` with the two items in your outer tuple. `Set((1,2,3,4,5,6))` works exactly as expected. If you’re getting the length 2 tuple from somewhere else, `Set(first(ntup))` works as expected.

If you would like to assert that the type of `ntup` is `NTuple{6,Int}`, the syntax you’re looking for is `ntup::NTuple{6,Int} = (1,2,3,4,5,)`.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 14, 2019, 8:48pm UTC](https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532/3 "2019-08-14T20:48:51Z")

</div>

Thank you!
