# How to loop over the key/value pairs of a NamedTuple?

**URL:** <https://discourse.julialang.org/t/how-to-loop-over-the-key-value-pairs-of-a-namedtuple/5470>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 20, 2017, 4:43am UTC](https://discourse.julialang.org/t/how-to-loop-over-the-key-value-pairs-of-a-namedtuple/5470 "2017-08-20T04:43:40Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 21, 2017, 10:10pm UTC](https://discourse.julialang.org/t/how-to-loop-over-the-key-value-pairs-of-a-namedtuple/5470/7 "2017-08-21T22:10:11Z")

</div>

@davidanthoff I am using @Tamas_Papp’s solution, thanks.

I still have an issue with using NamedTuple objects as described in this post though:

> [@Handling solver parameters elegantly in Julia](https://discourse.julialang.org/t/handling-solver-parameters-elegantly-in-julia/5269/11):
>
> @tshort, I am back to this issue after a while. I am giving NamedTuple a try, but couldn’t make the outer constructor below work: using Parameters: @with\_kw @with\_kw struct Param mean = 0. variance = 1. end struct Solver params::Dict{Symbol,Param} # inner ctor to be called from outside Solver(params::Dict{Symbol,Param}) = new(params) end # outer ctor with named tuples function Solver(params...) dict = Dict{Symbol,Param}() for (varname, varparams) in params push!(dict, varname …

Basically, I am trying to have an outer constructor with NamedTuples that get converted into an inner constructor with dictionaries. My attempt failed.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-loop-over-the-key-value-pairs-of-a-namedtuple/5470)._
