# \#namedtuple

**URL:** https://discourse.julialang.org/tag/namedtuple/484.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Merging disjoint NamedTuples](https://discourse.julialang.org/t/merging-disjoint-namedtuples/137650)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 3\
**Last updated:** [June 16, 2026, 1:10pm UTC](https://discourse.julialang.org/t/merging-disjoint-namedtuples/137650 "2026-06-16T13:10:54Z")

</div>

I need a function that merges two NamedTuples, but throws an error if they have elements in common. Not unlike @generated function merge\_disjoint(a::NamedTuple{A}, b::NamedTuple{B}) where {A,B} AB = intersect(A, B) …

---

## [Convert or Reinterpret Between NamedTuple and SVector](https://discourse.julialang.org/t/convert-or-reinterpret-between-namedtuple-and-svector/134600)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 7\
**Last updated:** [December 17, 2025, 7:33pm UTC](https://discourse.julialang.org/t/convert-or-reinterpret-between-namedtuple-and-svector/134600 "2025-12-17T19:33:07Z")

</div>

My question is related to Vector to NamedTuple? Assume my NamedTuple contains only floating point values T and SVector{N, T} entries, e.g., using StaticArrays nt = ( a = rand(), b = SA\[1.0, 2.0 ,3.0\] ) Taking such a N…

---

## [Permute NamedTuple based on names of another NamedTuple](https://discourse.julialang.org/t/permute-namedtuple-based-on-names-of-another-namedtuple/134088)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 3\
**Last updated:** [November 24, 2025, 7:51pm UTC](https://discourse.julialang.org/t/permute-namedtuple-based-on-names-of-another-namedtuple/134088 "2025-11-24T19:51:19Z")

</div>

I would like to perform a calculation in type space: given a NamedTuple{M,K} type, permute its fields so that the names match a NamedTuple{N}. Example: julia\> p1(NamedTuple{(:a,:b)}, NamedTuple{(:b,:a),Tuple{Int,Float64…

---

## [Showing a BitVector in NamedTuple](https://discourse.julialang.org/t/showing-a-bitvector-in-namedtuple/131048)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 17\
**Last updated:** [July 28, 2025, 5:37am UTC](https://discourse.julialang.org/t/showing-a-bitvector-in-namedtuple/131048 "2025-07-28T05:37:26Z")

</div>

I find a bit of inconsistency, probably about showing a NamedTuple julia\> v = \[1, 0, 1.\]; julia\> nt = (bitvec = Bool.(v),) # the following output is not accurate (bitvec = Bool\[1, 0, 1\],) julia\> nt.bitvec 3-element Bi…

---

## [Destructuring of NamedTuple in julia 1.10](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308)

<div class="topic-metadata">

**Author:** [@o314](https://discourse.julialang.org/u/o314)\
**Replies:** 3\
**Last updated:** [May 25, 2025, 2:35pm UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308 "2025-05-25T14:35:13Z")

</div>

I wonder if there is a way to destructure a namedtuple with splatting like this (; a, nt...) = (; a=1, b=2, c=3) where one is expecting to get a = 1 and nt = (; b=2, c=3) setted This forms fails @ home with julia v1.1…

---

## [From Named Tuple to Struct](https://discourse.julialang.org/t/from-named-tuple-to-struct/127927)

<div class="topic-metadata">

**Author:** [@Magnus\_Lilledahl](https://discourse.julialang.org/u/Magnus_Lilledahl)\
**Replies:** 2\
**Last updated:** [April 10, 2025, 2:35pm UTC](https://discourse.julialang.org/t/from-named-tuple-to-struct/127927 "2025-04-10T14:35:24Z")

</div>

Say I have a Named Tuple like a = (switch = dataframe1, swatch = dataframe2) and I have some structs struct switch df::DataFrame ...more fields end struct swatch df::DataFrame ...more fields end I want to ite…

---

## [Getting MutableNamedTuple keys from an empty array](https://discourse.julialang.org/t/getting-mutablenamedtuple-keys-from-an-empty-array/127387)

<div class="topic-metadata">

**Author:** [@s\_amap](https://discourse.julialang.org/u/s_amap)\
**Replies:** 18\
**Last updated:** [April 3, 2025, 8:58am UTC](https://discourse.julialang.org/t/getting-mutablenamedtuple-keys-from-an-empty-array/127387 "2025-04-03T08:58:29Z")

</div>

Hmm, I have an empty Vector of MutableNamedTuples with a specific signature, ie if the array has a single element, then I can recover the keys of the underlying NamedTuple by inspecting the element. But what if the arr…

---

## [How to change dims data from NT or T to ::OutDims for YAXArrays.DAT.OutputCube](https://discourse.julialang.org/t/how-to-change-dims-data-from-nt-or-t-to-outdims-for-yaxarrays-dat-outputcube/125700)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 0\
**Last updated:** [February 9, 2025, 9:17am UTC](https://discourse.julialang.org/t/how-to-change-dims-data-from-nt-or-t-to-outdims-for-yaxarrays-dat-outputcube/125700 "2025-02-09T09:17:41Z")

</div>

Hi guys, I am new to Julia, and wants to run a function which is like: outcubes = mapCube(TEMYax, (incubes...,); selected\_models=selected\_models, forcing\_vars=forcing.variables, output\_v…

---

## [Function arguments](https://discourse.julialang.org/t/function-arguments/61717)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 37\
**Last updated:** [December 20, 2024, 4:56pm UTC](https://discourse.julialang.org/t/function-arguments/61717 "2024-12-20T16:56:59Z")

</div>

Is it possible to pass a named tuple to a function and have the components available as variables without explicitly specifying them as arguments. f( X ) = A + B X = (A=1,B=2) f( X ) output : 3 Background: I have ab…

---

## [How to slice a NamedTuple?](https://discourse.julialang.org/t/how-to-slice-a-namedtuple/121767)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 6\
**Last updated:** [October 28, 2024, 5:14pm UTC](https://discourse.julialang.org/t/how-to-slice-a-namedtuple/121767 "2024-10-28T17:14:38Z")

</div>

How to? julia\> (;a=10, b=20, c=30)\[2:end\] ERROR: MethodError: no method matching getindex(::@NamedTuple{a::Int64, b::Int64, c::Int64}, ::UnitRange{Int64}) # Desired: (;b=20, c=30)

---

## [Vector{NamedTuple} vs Vector{@NamedTuple}?](https://discourse.julialang.org/t/vector-namedtuple-vs-vector-namedtuple/118111)

<div class="topic-metadata">

**Author:** [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Replies:** 4\
**Last updated:** [August 13, 2024, 5:45am UTC](https://discourse.julialang.org/t/vector-namedtuple-vs-vector-namedtuple/118111 "2024-08-13T05:45:12Z")

</div>

How can I open my function method to work on all NamedTuples collected into a Vector? I don’t understand why this isn’t working. function multicall(f::Function, user\_inputs::Vector{NamedTuple}; kwargs...) out = \[\] …

---

## [Dict of NamedTuple](https://discourse.julialang.org/t/dict-of-namedtuple/112836)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 4\
**Last updated:** [April 11, 2024, 5:34pm UTC](https://discourse.julialang.org/t/dict-of-namedtuple/112836 "2024-04-11T17:34:56Z")

</div>

Hello ! :grinning: I have a question about a behavior I don’t understand when I try to make a dictionary composed of NamedTuple. Each of these NamedTuple corresponds to a parameter set of a simulation. For example: ju…

---

## [Custom NamedTuple dynamic creation](https://discourse.julialang.org/t/custom-namedtuple-dynamic-creation/109807)

<div class="topic-metadata">

**Author:** [@ImreMD](https://discourse.julialang.org/u/ImreMD)\
**Replies:** 5\
**Last updated:** [February 6, 2024, 4:40pm UTC](https://discourse.julialang.org/t/custom-namedtuple-dynamic-creation/109807 "2024-02-06T16:40:32Z")

</div>

Hello guys, wondering if there’s a way of dynamically assign keys to a NamedTuple something like this: function create\_named\_tuple(x, y, z) mynames = (:position, :y, :z) mydata = (x, "free","get") return NamedTup…

---

## [Reduce allocations when extracting values from NamedTuples](https://discourse.julialang.org/t/reduce-allocations-when-extracting-values-from-namedtuples/108570)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 12\
**Last updated:** [January 12, 2024, 1:18pm UTC](https://discourse.julialang.org/t/reduce-allocations-when-extracting-values-from-namedtuples/108570 "2024-01-12T13:18:51Z")

</div>

Hello, I have a situation where I need to extract values from NamedTuples which are embedded within structs. Unfortunately, there are a lot of allocations, and it is not type stable. I have created a MWE below. mutable…

---

## [Allocations from selecting fields of a named tuple](https://discourse.julialang.org/t/allocations-from-selecting-fields-of-a-named-tuple/108112)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 4\
**Last updated:** [December 28, 2023, 12:53pm UTC](https://discourse.julialang.org/t/allocations-from-selecting-fields-of-a-named-tuple/108112 "2023-12-28T12:53:29Z")

</div>

There seems to be a large difference in the number allocations when selecting fields from a named tuple via two different approaches. using BenchmarkTools nt = (a=1, b=2, c=3) t = (:b, :c) If I use getindex, I get 6 al…

---

## [Arithmetic operations with NamedTuples](https://discourse.julialang.org/t/arithmetic-operations-with-namedtuples/107140)

<div class="topic-metadata">

**Author:** [@fusion809](https://discourse.julialang.org/u/fusion809)\
**Replies:** 8\
**Last updated:** [December 6, 2023, 8:50pm UTC](https://discourse.julialang.org/t/arithmetic-operations-with-namedtuples/107140 "2023-12-06T20:50:52Z")

</div>

I often use Julia to calculate the nutrition of my meals. I know there are calculators for this online, but I prefer doing this myself in Julia. I normally do this by first defining NamedTuples with the nutritional infor…

---

## [Accessing a ComponentArray's fields in a type-stable manner](https://discourse.julialang.org/t/accessing-a-componentarrays-fields-in-a-type-stable-manner/103832)

<div class="topic-metadata">

**Author:** [@Bizzi](https://discourse.julialang.org/u/Bizzi)\
**Replies:** 2\
**Last updated:** [October 31, 2023, 3:53am UTC](https://discourse.julialang.org/t/accessing-a-componentarrays-fields-in-a-type-stable-manner/103832 "2023-10-31T03:53:15Z")

</div>

I’m struggling with iterating over the named fields of a ComponentArray in a compiler-friendly way. Take the following MWE, emulating some Neural Network: I create the nested structure layers, containing some weight …

---

## [RegexMatch to NamedTuple?](https://discourse.julialang.org/t/regexmatch-to-namedtuple/22551)

<div class="topic-metadata">

**Author:** [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Replies:** 3\
**Last updated:** [August 20, 2023, 5:42pm UTC](https://discourse.julialang.org/t/regexmatch-to-namedtuple/22551 "2023-08-20T17:42:28Z")

</div>

When parsing a string with regex like m = match(r"^(?\<str\_a\>\\S+) (?\<str\_b\>\\S+)$", "abc def") it is possible to get group values like m\[:str\_a\] and so on. But how do I convert the match to namedtuple, (str\_a = "abc", str\_…

---

## [Julia NaN check for NamedTuple](https://discourse.julialang.org/t/julia-nan-check-for-namedtuple/102583)

<div class="topic-metadata">

**Author:** [@iHany](https://discourse.julialang.org/u/iHany)\
**Replies:** 4\
**Last updated:** [August 8, 2023, 7:00am UTC](https://discourse.julialang.org/t/julia-nan-check-for-namedtuple/102583 "2023-08-08T07:00:39Z")

</div>

How to check if NaN is in a given NamedTuple? For example, julia\> myarray = \[0, 1, 2, NaN\] 4-element Vector{Float64}: 0.0 1.0 2.0 NaN julia\> isnan.(myarray) 4-element BitVector: 0 0 0 1 julia\> mynt = (;…

---

## [Deep copy of Array in Struct in NamedTuple](https://discourse.julialang.org/t/deep-copy-of-array-in-struct-in-namedtuple/102349)

<div class="topic-metadata">

**Author:** [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Replies:** 3\
**Last updated:** [August 1, 2023, 12:17pm UTC](https://discourse.julialang.org/t/deep-copy-of-array-in-struct-in-namedtuple/102349 "2023-08-01T12:17:47Z")

</div>

I am creating and returning a NamedTuple cache mystruct = MyStruct{Float64}(42, 42, 42) cache = (; foo, bar, mystruct) return cache where mystruct is an object of the mutable struct MyStruct which contains an array mu…

---

## [Constructors for structs with NamedTuple fields](https://discourse.julialang.org/t/constructors-for-structs-with-namedtuple-fields/101758)

<div class="topic-metadata">

**Author:** [@sadish-d](https://discourse.julialang.org/u/sadish-d)\
**Replies:** 23\
**Last updated:** [July 21, 2023, 12:26am UTC](https://discourse.julialang.org/t/constructors-for-structs-with-namedtuple-fields/101758 "2023-07-21T00:26:07Z")

</div>

I am creating a struct with a field that is a named tuple. I am getting different behavior when I define a constructor inside vs. outside the struct. Below, F1() runs fine but F2() gives a “UndefVarError: T not defined” …

---

## [How to make a named tuple from a dictionary?](https://discourse.julialang.org/t/how-to-make-a-named-tuple-from-a-dictionary/10899)

<div class="topic-metadata">

**Author:** [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Replies:** 40\
**Last updated:** [June 23, 2023, 1:04pm UTC](https://discourse.julialang.org/t/how-to-make-a-named-tuple-from-a-dictionary/10899 "2023-06-23T13:04:37Z")

</div>

Is there a simple way to make a named tuple from a Dict{Symbol, T}?

---

## [Why map function in named tuple is outputing only one item](https://discourse.julialang.org/t/why-map-function-in-named-tuple-is-outputing-only-one-item/99410)

<div class="topic-metadata">

**Author:** [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Replies:** 3\
**Last updated:** [May 25, 2023, 9:40pm UTC](https://discourse.julialang.org/t/why-map-function-in-named-tuple-is-outputing-only-one-item/99410 "2023-05-25T21:40:37Z")

</div>

Hello, good afternoon Why this named tuple is being outputed with a single mean when using map function? aq = readdlm("data.dat") data = (set1=(x=aq\[:,1\], y=aq\[:, 2\]), set2=(x=aq\[:,3\], y=aq\[:, 4\]), set3=(x=aq\[:…

---

## [Construct Tuple containing NamedTuple from Tuple](https://discourse.julialang.org/t/construct-tuple-containing-namedtuple-from-tuple/98954)

<div class="topic-metadata">

**Author:** [@baumgold](https://discourse.julialang.org/u/baumgold)\
**Replies:** 8\
**Last updated:** [May 19, 2023, 2:46pm UTC](https://discourse.julialang.org/t/construct-tuple-containing-namedtuple-from-tuple/98954 "2023-05-19T14:46:52Z")

</div>

I’m trying to construct a Tuple containing a member NamedTuple from a Tuple. I believe this should work but it doesn’t. julia\> T = Tuple{Int64, Int64, NamedTuple{(:d, :e), Tuple{Int64, Int64}}}; julia\> vals = (1,2,(3,…

---

## [Convert Dict to NamedTuple](https://discourse.julialang.org/t/convert-dict-to-namedtuple/98140)

<div class="topic-metadata">

**Author:** [@Brinkhuis](https://discourse.julialang.org/u/Brinkhuis)\
**Replies:** 4\
**Last updated:** [April 30, 2023, 8:13pm UTC](https://discourse.julialang.org/t/convert-dict-to-namedtuple/98140 "2023-04-30T20:13:30Z")

</div>

I’m looking for a clean way to convert Dictionaries into NamedTuples. I found a helpful topic, however, that solution only works for Dicts with symbol keys. julia\> (; Dict(:a =\> 5, :b =\> 6, :c =\> 7)…) (a = 5, b = 6, …

---

## [Sort keys of NamedTuple](https://discourse.julialang.org/t/sort-keys-of-namedtuple/94630)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 5\
**Last updated:** [February 15, 2023, 5:41pm UTC](https://discourse.julialang.org/t/sort-keys-of-namedtuple/94630 "2023-02-15T17:41:20Z")

</div>

I would like to sort a NamedTuple alphabetically by its keys. For instance: (b=1, a=2, c=3) ---\> (a=2, b=1, c=3) (a=1, c=2, b=3) ---\> (a=1, b=3, c=2) I am pretty sure such functionality already exists, where to look fo…

---

## [Creating a struct from a Named Tuple](https://discourse.julialang.org/t/creating-a-struct-from-a-named-tuple/94586)

<div class="topic-metadata">

**Author:** [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Replies:** 7\
**Last updated:** [February 14, 2023, 2:15pm UTC](https://discourse.julialang.org/t/creating-a-struct-from-a-named-tuple/94586 "2023-02-14T14:15:36Z")

</div>

Is there any function like similar which creates a struct inhering the names and types of a NamedTuple? MEW: nt = (a = 1, b ="Hello") #some function like MyStruct = similar(nt) #\`similar\` would create this: struct M…

---

## [Enabling broadcasting for named tuples alt. broadcast? broadcasted? broadcastable? BroadcastStyle?](https://discourse.julialang.org/t/enabling-broadcasting-for-named-tuples-alt-broadcast-broadcasted-broadcastable-broadcaststyle/94468)

<div class="topic-metadata">

**Author:** [@Euhan](https://discourse.julialang.org/u/Euhan)\
**Replies:** 1\
**Last updated:** [February 13, 2023, 11:59am UTC](https://discourse.julialang.org/t/enabling-broadcasting-for-named-tuples-alt-broadcast-broadcasted-broadcastable-broadcaststyle/94468 "2023-02-13T11:59:44Z")

</div>

Like many before me (if my googling serves me right), I found myself in need of broadcasting over named tuples. In this case it is in the hope that I can get MLUtils.jl to handle batches that are (you guessed it) named t…

---

## [Is there something like the get() function for namedTuples?](https://discourse.julialang.org/t/is-there-something-like-the-get-function-for-namedtuples/92463)

<div class="topic-metadata">

**Author:** [@rakshith95](https://discourse.julialang.org/u/rakshith95)\
**Replies:** 3\
**Last updated:** [January 4, 2023, 10:50am UTC](https://discourse.julialang.org/t/is-there-something-like-the-get-function-for-namedtuples/92463 "2023-01-04T10:50:18Z")

</div>

Hello, Is there an equivalent of the get() function for dictionaries for NamedTuples? I want to get the value for the ‘key’ of a NamedTuple if it exists, and if it does not assign it to some default value; pretty much …

---

## [Experiment: NamedTuple Syntax w/ Type Declarations](https://discourse.julialang.org/t/experiment-namedtuple-syntax-w-type-declarations/91988)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 3\
**Last updated:** [December 22, 2022, 3:27am UTC](https://discourse.julialang.org/t/experiment-namedtuple-syntax-w-type-declarations/91988 "2022-12-22T03:27:57Z")

</div>

We have builtin syntax sugar for declaring NamedTuples like so: julia\> a, b, c, d = 1, 2, 3, 4 (1, 2, 3, 4) julia\> (; a=1, b=2, c, d) (a = 1, b = 2, c = 3, d = 4) However, if we wish to declare types (e.g. :a as Numbe…

[Next page](https://discourse.julialang.org/tag/namedtuple/484.md?match_all_tags=true&page=1&tags%5B%5D=namedtuple)
