From adb4e071e688534fd7c163719f005239cd2f7c25 Mon Sep 17 00:00:00 2001 From: franczc Date: Mon, 11 Nov 2019 16:31:22 +1000 Subject: Adding dictionary entry using string variable as key. --- docs/markdown/snippets/add_dictionary_variable_key.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/markdown/snippets/add_dictionary_variable_key.md (limited to 'docs/markdown/snippets') diff --git a/docs/markdown/snippets/add_dictionary_variable_key.md b/docs/markdown/snippets/add_dictionary_variable_key.md new file mode 100644 index 0000000..373ce04 --- /dev/null +++ b/docs/markdown/snippets/add_dictionary_variable_key.md @@ -0,0 +1,17 @@ +## Adding dictionary entry using string variable as key + +New dictionary entry can now be added using string variable as key, +in addition to using string literal as key. + +```meson +dict = {} + +# A variable to be used as a key +key = 'myKey' + +# Add new entry using the variable +dict += {key : 'myValue'} + +# Test that the stored value is correct +assert(dict[key] == 'myValue', 'Incorrect value retrieved from dictionary') +``` -- cgit v1.1