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

2

Comments

  1. The :delete adverb removes the entry from the hash (here we ignore the value it returns).

  2. The hash started with three entries and now has 2, confirming that one was removed. Counting with .elems keeps the output predictable without depending on the order of the keys.

Course navigation

Delete a key   |   Key and value