Iterate over deepest values in a nested AssociationJoinAcross on nested association by nested keyExtract all Values from nested AssociationHow to check keys and values in nested Associations?Table from grouping an association by valueUsing Case to pull Keys and Values out of a nested AssociationReplacing values in an association based on keysRename Keys in Nested Association`Transpose` nested `Association`Keyed eigensystem for nested AssociationIterate over keys of association
I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again
Where to connect the fuse and why?
A quine of sorts
Undetectable mail tracker
Can a successful book series let the bad guy win?
Word ending in "-ine" for rat-like
pgfmath does not work
If a USA citizen marries a foreign citizen who has a kid from a previous marriage
If I were to build a J3 cub twice the size of the original using the same CG would it fly?
How to securely dispose of a smartphone?
Sharing referee/AE report online to point out a grievous error in refereeing
List manipulation: conditional result based on variable-length sublists
Why is this double switch controlling both light circuits from both switches?
List Manipulation : a,b,c,d,e,f,g,h into a,b,c,d,e,f,g,h
/etc/hosts not working
Why would anyone even use a Portkey?
How can combining souls together not increase its volume?
Why was p[:] designed to work differently in these two situations?
How could an armless race establish civilization?
Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?
How can I open this door latch with the knobs removed?
Why did the Apple //e make a hideous noise if you inserted the disk upside down?
Is it okay to fade a human face just to create some space to place important content over it?
What game is this character in the Pixels movie from?
Iterate over deepest values in a nested Association
JoinAcross on nested association by nested keyExtract all Values from nested AssociationHow to check keys and values in nested Associations?Table from grouping an association by valueUsing Case to pull Keys and Values out of a nested AssociationReplacing values in an association based on keysRename Keys in Nested Association`Transpose` nested `Association`Keyed eigensystem for nested AssociationIterate over keys of association
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Is it possible to iterate over the values of the deepest layer of keys in a nested association? For example:
assoc = <| "a"->0, "b"-> <| "c"->"one" ,"d"->2 , "e"->3|>, "f"->4|>
Would it be possible to iterate over just the values of at the deepest level in this example 0,"one",2,3,4
? Or, possible to iterate over the deepest level of keys such that I could test the type for the value of each key?
expression-manipulation associations iteration
$endgroup$
add a comment |
$begingroup$
Is it possible to iterate over the values of the deepest layer of keys in a nested association? For example:
assoc = <| "a"->0, "b"-> <| "c"->"one" ,"d"->2 , "e"->3|>, "f"->4|>
Would it be possible to iterate over just the values of at the deepest level in this example 0,"one",2,3,4
? Or, possible to iterate over the deepest level of keys such that I could test the type for the value of each key?
expression-manipulation associations iteration
$endgroup$
add a comment |
$begingroup$
Is it possible to iterate over the values of the deepest layer of keys in a nested association? For example:
assoc = <| "a"->0, "b"-> <| "c"->"one" ,"d"->2 , "e"->3|>, "f"->4|>
Would it be possible to iterate over just the values of at the deepest level in this example 0,"one",2,3,4
? Or, possible to iterate over the deepest level of keys such that I could test the type for the value of each key?
expression-manipulation associations iteration
$endgroup$
Is it possible to iterate over the values of the deepest layer of keys in a nested association? For example:
assoc = <| "a"->0, "b"-> <| "c"->"one" ,"d"->2 , "e"->3|>, "f"->4|>
Would it be possible to iterate over just the values of at the deepest level in this example 0,"one",2,3,4
? Or, possible to iterate over the deepest level of keys such that I could test the type for the value of each key?
expression-manipulation associations iteration
expression-manipulation associations iteration
edited 7 hours ago
b3m2a1
30.3k3 gold badges61 silver badges179 bronze badges
30.3k3 gold badges61 silver badges179 bronze badges
asked 8 hours ago
hoodedarcherhoodedarcher
1258 bronze badges
1258 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
Level[assoc, -1]
(* 0, "one", 2, 3, 4 *)
$endgroup$
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
add a comment |
$begingroup$
Map[
AssociationMap[
keyTest[#[[1]]] -> valueTest[#[[2]]] &
],
<|"a" -> 0, "b" -> <|"c" -> "one", "d" -> 2, "e" -> 3|>, "f" -> 4|>,
-2
]
<|"a" -> 0,
"b" -> <|keyTest["c"] -> valueTest["one"], keyTest["d"] -> valueTest[2],
keyTest["e"] -> valueTest[3]|>, "f" -> 4|>
$endgroup$
add a comment |
$begingroup$
assoc /. Association -> (Values@*List) // Flatten
0, "one", 2, 3, 4
When some values are non-atomic this approach and the deepest Level
approach give different results:
assoc2 = <| "a" -> foo[0], "b" -> <| "c" -> "one" , "d" -> 2 , "e" -> 3|>,
"f" -> bar[1], foo[3]|>;
assoc2 /. Association -> (Values@*List) // Flatten
foo[0], "one", 2, 3, bar[1], foo[3]
Level[assoc2, -1]
0, "one", 2, 3, 1, 3
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201128%2fiterate-over-deepest-values-in-a-nested-association%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Level[assoc, -1]
(* 0, "one", 2, 3, 4 *)
$endgroup$
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
add a comment |
$begingroup$
Level[assoc, -1]
(* 0, "one", 2, 3, 4 *)
$endgroup$
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
add a comment |
$begingroup$
Level[assoc, -1]
(* 0, "one", 2, 3, 4 *)
$endgroup$
Level[assoc, -1]
(* 0, "one", 2, 3, 4 *)
answered 8 hours ago


RomanRoman
12k1 gold badge19 silver badges46 bronze badges
12k1 gold badge19 silver badges46 bronze badges
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
add a comment |
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
$begingroup$
That is pretty nifty. Thanks!
$endgroup$
– kickert
7 hours ago
add a comment |
$begingroup$
Map[
AssociationMap[
keyTest[#[[1]]] -> valueTest[#[[2]]] &
],
<|"a" -> 0, "b" -> <|"c" -> "one", "d" -> 2, "e" -> 3|>, "f" -> 4|>,
-2
]
<|"a" -> 0,
"b" -> <|keyTest["c"] -> valueTest["one"], keyTest["d"] -> valueTest[2],
keyTest["e"] -> valueTest[3]|>, "f" -> 4|>
$endgroup$
add a comment |
$begingroup$
Map[
AssociationMap[
keyTest[#[[1]]] -> valueTest[#[[2]]] &
],
<|"a" -> 0, "b" -> <|"c" -> "one", "d" -> 2, "e" -> 3|>, "f" -> 4|>,
-2
]
<|"a" -> 0,
"b" -> <|keyTest["c"] -> valueTest["one"], keyTest["d"] -> valueTest[2],
keyTest["e"] -> valueTest[3]|>, "f" -> 4|>
$endgroup$
add a comment |
$begingroup$
Map[
AssociationMap[
keyTest[#[[1]]] -> valueTest[#[[2]]] &
],
<|"a" -> 0, "b" -> <|"c" -> "one", "d" -> 2, "e" -> 3|>, "f" -> 4|>,
-2
]
<|"a" -> 0,
"b" -> <|keyTest["c"] -> valueTest["one"], keyTest["d"] -> valueTest[2],
keyTest["e"] -> valueTest[3]|>, "f" -> 4|>
$endgroup$
Map[
AssociationMap[
keyTest[#[[1]]] -> valueTest[#[[2]]] &
],
<|"a" -> 0, "b" -> <|"c" -> "one", "d" -> 2, "e" -> 3|>, "f" -> 4|>,
-2
]
<|"a" -> 0,
"b" -> <|keyTest["c"] -> valueTest["one"], keyTest["d"] -> valueTest[2],
keyTest["e"] -> valueTest[3]|>, "f" -> 4|>
answered 8 hours ago
b3m2a1b3m2a1
30.3k3 gold badges61 silver badges179 bronze badges
30.3k3 gold badges61 silver badges179 bronze badges
add a comment |
add a comment |
$begingroup$
assoc /. Association -> (Values@*List) // Flatten
0, "one", 2, 3, 4
When some values are non-atomic this approach and the deepest Level
approach give different results:
assoc2 = <| "a" -> foo[0], "b" -> <| "c" -> "one" , "d" -> 2 , "e" -> 3|>,
"f" -> bar[1], foo[3]|>;
assoc2 /. Association -> (Values@*List) // Flatten
foo[0], "one", 2, 3, bar[1], foo[3]
Level[assoc2, -1]
0, "one", 2, 3, 1, 3
$endgroup$
add a comment |
$begingroup$
assoc /. Association -> (Values@*List) // Flatten
0, "one", 2, 3, 4
When some values are non-atomic this approach and the deepest Level
approach give different results:
assoc2 = <| "a" -> foo[0], "b" -> <| "c" -> "one" , "d" -> 2 , "e" -> 3|>,
"f" -> bar[1], foo[3]|>;
assoc2 /. Association -> (Values@*List) // Flatten
foo[0], "one", 2, 3, bar[1], foo[3]
Level[assoc2, -1]
0, "one", 2, 3, 1, 3
$endgroup$
add a comment |
$begingroup$
assoc /. Association -> (Values@*List) // Flatten
0, "one", 2, 3, 4
When some values are non-atomic this approach and the deepest Level
approach give different results:
assoc2 = <| "a" -> foo[0], "b" -> <| "c" -> "one" , "d" -> 2 , "e" -> 3|>,
"f" -> bar[1], foo[3]|>;
assoc2 /. Association -> (Values@*List) // Flatten
foo[0], "one", 2, 3, bar[1], foo[3]
Level[assoc2, -1]
0, "one", 2, 3, 1, 3
$endgroup$
assoc /. Association -> (Values@*List) // Flatten
0, "one", 2, 3, 4
When some values are non-atomic this approach and the deepest Level
approach give different results:
assoc2 = <| "a" -> foo[0], "b" -> <| "c" -> "one" , "d" -> 2 , "e" -> 3|>,
"f" -> bar[1], foo[3]|>;
assoc2 /. Association -> (Values@*List) // Flatten
foo[0], "one", 2, 3, bar[1], foo[3]
Level[assoc2, -1]
0, "one", 2, 3, 1, 3
edited 3 hours ago
answered 4 hours ago
kglrkglr
201k10 gold badges230 silver badges458 bronze badges
201k10 gold badges230 silver badges458 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201128%2fiterate-over-deepest-values-in-a-nested-association%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown