Dictionary functions
This topic describes the syntax, description, parameters, and response parameters of dictionary functions. This topic also provides examples of these functions.
set
Use the set function to add or update a key-value pair in a dictionary.
Item | Description |
Syntax | set(d, k, v) |
Parameters |
|
Examples |
|
Return value | This function always returns
|
get
Use the get function to retrieve the value associated with a specified key from a dictionary.
Item | Description |
Syntax | get(d, k) |
Parameters |
|
Example | |
Return value | If the key exists, the function returns its corresponding value. Otherwise, it returns |
foreach
The foreach function has the following behaviors:
It iterates over each key-value pair in the dictionary
dand executes the callback functionf.The callback function
fmust have the signaturef(key, value, user_data).The
foreach()loop terminates if thef()callback function returnsfalse.
Item | Description |
Syntax | foreach(d, f, user_data) |
Parameters |
|
Examples |
|
Return value | This function always returns
|
del
Deletes key-value pairs from a dictionary (d). The following tables describes the details about this function.
Item | Description |
Syntax | del(d, k) |
Parameters |
|
Examples | |
Response parameters | Returns a value of true. Response parameter for this example: |