How to make a named tuple from a dictionary?

I don’t think it is a good idea, because, as I remarked above, Dicts are not ordered, so it can happen that two <:AbstractDict values are == but the resulting NamedTuples aren’t.

It may be the version – I do not have v1.0.3 available …
you have a way that works, so I am not looking further

1 Like
julia> adict = Dict("astr" => 5, "bstr" => 'b');

julia> (; (Symbol(k) => v for (k,v) in adict)...)
(bstr = 'b', astr = 5)

There already is a much more general constructor which takes any iterator yielding Symbol => value pairs. People just don’t know about the syntax (hence https://github.com/JuliaLang/julia/pull/32330).

3 Likes