Course of Raku / Advanced / Containers / Subscript adverbs 🆕 / Exercises / Key and value

Solution: Key and value

Here is a possible solution to the task.

Code

my %h = x => 10, y => 20;
say %h<x>:kv;

🦋 You can find the source code in the file key-and-value.raku.

Output

(x 10)

Comments

  1. The :kv adverb returns both the key and the value as a list.

  2. For a hash, the key is the name you subscript with, so %h<x>:kv gives the list (x 10).

Course navigation

Key and value   |   Special and dynamic variables 🆕