Course of Raku / Advanced / Containers / Subscript adverbs 🆕 / Exercises / Delete a key
Solution: Delete a key
Here is a possible solution to the task.
Code
my %h = a => 1, b => 2, c => 3;
%h<b>:delete;
say %h.elems;🦋 You can find the source code in the file delete-a-key.raku.
Output
2Comments
The
:deleteadverb removes the entry from the hash (here we ignore the value it returns).The hash started with three entries and now has
2, confirming that one was removed. Counting with.elemskeeps the output predictable without depending on the order of the keys.
Course navigation
← Delete a key | Key and value →