How to select only some values of an association based on some criteria

Here is the association I have:

assc = {"abc" -> 2.456, "efg" -> 3.652, "_final" -> 6.108}


I need to remove all key-value pairs where keys start with '_'. I am new to Mathematica, so can anyone please help me out with this. I have a condition (mentioned below), I just don't know how to apply it on an association using 'select'?

The condition I have is:

(StringStartsQ[Keys[assc], "_"])

Output:= {False, False, False, False, False, False, False, False, False, \
False, False, False, False, False, True, True, True, True, True}

• Try Pick[assc, StringStartsQ[Keys[assc], Except["_"]]] Jun 15, 2018 at 19:30
• Point of information: assc = {"abc" -> 2.456, ... } is a list of rules not an association. Jun 15, 2018 at 20:20

Select

Select[
assc
, Not[
StringStartsQ[
Keys[#]
, "_"
]
] &
]


DeleteCases

DeleteCases[
assc
, _?(StringStartsQ[Keys[#], "_"] &)
]


KeySelect

Thanks to @JasonB for this solution.

KeySelect[
assc
, Not@*StringStartsQ["_"]
]

• You can shorten it a bit with KeySelect[ assc, Not@*StringStartsQ["_"]] Jun 15, 2018 at 19:26
• @JasonB. Thanks! Didn't know about that one! Incorporated to the answer. Jun 15, 2018 at 19:29
• @rhermans: Thank you so much for your help. Unfortunately the solutions using 'Select' and 'DeleteCases' did not produce the correct result, I'm still trying on making it work. Jun 15, 2018 at 22:17
• @JasonB. Thank you! The solution worked. Much appreciated! :) Jun 15, 2018 at 22:18
• @Rajat Bhattacharjee Your edit was somewhat too extensive. That's why I voted for its rejection. However, I see that you found several caveats and their resolutions. Hence, I would like to encourage you to post your edit it as a separate answer. Jun 15, 2018 at 22:42