# Construct NamedTuple dynamically

**URL:** <https://discourse.julialang.org/t/construct-namedtuple-dynamically/15394>\
**Category:** General Usage\
**Tags:** namedtuple\
**Created:** [September 23, 2018, 6:26pm UTC](https://discourse.julialang.org/t/construct-namedtuple-dynamically/15394 "2018-09-23T18:26:45Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 23, 2018, 6:33pm UTC](https://discourse.julialang.org/t/construct-namedtuple-dynamically/15394/3 "2018-09-23T18:33:17Z")

</div>

Answering my own question. I should have read this post first.

> [@\[ANN\] NamedTupleTools.jl](https://discourse.julialang.org/t/ann-namedtupletools-jl/15374):
>
> [NamedTupleTools](https://github.com/JeffreySarnoff/NamedTupleTools.jl) is a small package that makes doing a few things with NamedTuples a bit easier. (Julia v1.0) using NamedTupleTools julia\> namedtuple(:a, :b, :c)(1, 2.0, "three") (a = 1, b = 2.0, c = "three") #= namedtuple( name1, name2, .. ) namedtuple( (name1, name2, ..) ) where the `names` are all `Symbols` or all `Strings` Generate a NamedTuple prototype by specifying or obtaining the fieldnames. The prototype is applied to fieldvalues, giving a completed NamedTuple. =# …

The solution:

```julia
julia> using NamedTupleTools

julia> nt = namedtuple(Symbol.(["a", "b", "c"])...)
NamedTuple{(:a, :b, :c),T} where T<:Tuple

julia> nt.([1, 2.0, "hello world"]...)
(a = 1, b = 2.0, c = "hello world")

```

---

_[View the full topic](https://discourse.julialang.org/t/construct-namedtuple-dynamically/15394)._
