This topic describes the syntax, description, parameters, and return values of dictionary functions. This topic also provides examples of these functions.
set
Sets key-value pairs in a dictionary specified by the d parameter. The following table
describes the details about this function.
Item | Description |
---|---|
Syntax | set(d, k, v) |
Parameters |
|
Examples |
|
Response parameters | Returns a value of true. Response parameters of Example 1 and Example 2:
|
get
Retrieves the value (v) that corresponds to a key (k) from a dictionary (d). The following
table describes the details about this function.
Item | Description |
---|---|
Syntax | get(d, k) |
Parameters |
|
Examples |
|
Response parameters | If the function succeeds, the value that corresponds to the specified key is returned.
Otherwise, a value of false is returned. Response parameters of this example:
|
foreach
Details about this function:
- Traverses elements in a dictionary (d) and calls a callback function (f) for each element.
- Specify the f parameter in the syntax of
f(key, value, user_data)
. - When the
f()
function returns false, theforeach()
loop ends.
Item | Description |
---|---|
Syntax | foreach(d, f, user_data) |
Parameters |
|
Examples |
|
Response parameters | Returns a value of true. Response parameters of Example 1 and Example 2:
|
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:
|
insert
Inserts elements into a dictionary. The following table describes the details about
this function.
Item | Description |
---|---|
Syntax | insert(list, value, [,pos]) |
Parameter |
|
Example |
|
Return value | This function always returns a value of true. Return value in this example:
|
sort
Sorts elements in a dictionary in the default order. The following table describes
the details about this function.
Item | Description |
---|---|
Syntax | sort(list[, comp]) |
Feature | If you specify the comp parameter, it must be a function that supports two elements in the specified dictionary as its parameters. A value of true is returned if the first element is placed before the second element. Therefore, a value of true is returned after the elements in the not comp(a, b) function are sorted. If you do not specify the comp parameter, the elements are sorted based on ANSII codes in ascending order. However, this sorting algorithm is unstable and may change the original order of two elements that have the same rank in the ANSII table. |
Parameter |
|
Example |
|
Return value | This function always returns a value of true. Return values in this example:
|
remove
Removes the element from the specified position in a dictionary and returns the removed
element. If you do not specify the pos parameter, the element that is at the end of
the dictionary is removed. The following table describes the details about this function.
Item | Description |
---|---|
Syntax | remove(list, [, pos]) |
Parameter |
|
Example |
|
Return value | Returns the element that is removed from the specified position. Return value in this
example:
|