# How to switch keys in a Map to Association [closed]

I have an association that has parameters for a function. These parameters represent two cases that need to be applied to the function. Some parameter values are common to both cases but some are unique to each case.

I need to execute the function for both cases of the parameters. I get the parameters for both cases in a single list per event. I've represented this below for a function f[a,b,c] where parameters a and b are common to both cases but for parameter c case 1 uses c1 and case 2 uses c2.

assoc = AssociationThread[{"a", "b", "c1", "c2"}, #] & /@ RandomInteger[20, {3, 4}];


So far I've managed to get the two list of the function calls but the parameter c in the function call is not evaluating to the value of the association; see below. I've not been able to figure out how to get the Key function to return the value of the key when it is mapped.

Transpose[(Function[{k}, f[#a, #b, Key[k]]] /@ {"c1", "c2"}) & /@ assoc]
(*
{{f[13, 7, Key["c1"]], f[5, 11, Key["c1"]], f[6, 16, Key["c1"]]},
{f[13, 7, Key["c2"]], f[5, 11, Key["c2"]], f[6, 16, Key["c2"]]}}
*)


How do I proceed? I've thought of using MapIndexed but it seems like a lot of mapping and remapping to get the result. I think there must be a cleaner way to get this. Yes?

## closed as off-topic by Mr.Wizard♦Apr 22 '15 at 16:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

• Use #[[Key[k]]]]. Btw it's hard to understand what you are trying to do. – C. E. Apr 22 '15 at 15:03
• What is your desired output? Your description is very hard to follow... – Stefan R Apr 22 '15 at 15:34
• @StefanR I've updated the question to be more clear. – Edmund Apr 22 '15 at 15:53

## 1 Answer

You can replace Key[k] with #[[Key[k]]].

• With this I was able to realize that I can replace Key[k] with just #[k] since it is the association that is being mapped in. For some reason I was thinking that each value was being mapped in. I think I've been looking at the screen for too long. :) – Edmund Apr 22 '15 at 16:25
• @Edmund Shall I close this as "simple mistake" in that case? – Mr.Wizard Apr 22 '15 at 16:34
• @Mr.Wizard Sure. – Edmund Apr 22 '15 at 16:38