Skip to main content

Dictionaries

In this section below, displays all of the Dictionary methods available in Jaseci for manipulating dictionaries. These methods provide a comprehensive and efficient way to work with dictionaries in Jac program.

items

Op.dict::items
Argskey, default
DescriptionReturns value of key if exists otherwise default.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
report _dict.dict::items;
}

Expected Output

"report": [
[
["key1","value1"],
["key2","value2"],
["key3","value3"]
]
]

keys

Op.dict::keys
ArgsNone
DescriptionReturn keys of the dictionary.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
report _dict.dict::keys;
}

Expected Output

 "report": [
["key1","key2","key3"]
]

values

Op.dict::values
ArgsNone
DescriptionReturn all the values in the dictionary.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
report _dict.dict::values;
}

Expected Output

"report": [
[
"value1",
"value2",
"value3"
]
]

copy

Op.dict::copy
ArgsNone
DescriptionReturns a shallow copy of the dictionary.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
_dict_copy = _dict.dict::copy;

report _dict_copy;
}

Expected Output

 "report" : [
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
]

deepcopy

Op.dict::deepcopy
ArgsNone
DescriptionReturns a deep copy of the dictionary.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
_dict_deepcopy = _dict.dict::deepcopy ;

report _dict_deepcopy;
}

Expected Output

"report": [
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
]

popitem

Op.dict::popitem
ArgsNone
DescriptionPops the last key value pair from the dictionary.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
_dict.dict::popitem;
report _dict;
}

Expected Output

"report": [
{
"key1": "value1",
"key2": "value2"
}
]

pop

Op.dict::pop
ArgsA key from the dict
DescriptionPops the value from the dictionary where the key is given.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
_dict.dict::pop("key1");
report _dict;
}

Expected Output

"report": [
{
"key2": "value2",
"key3": "value3"
}
]

update

Op.dict::update
ArgsDictionary object. (Ex: Dict {"key" : "new value"})
DescriptionUpdates items in the dictionary item with new value.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
_dict.dict::update({'key3': "value4"});
report _dict;
}

Expected Output

  "report": [
{
"key1": "value1",
"key2": "value2",
"key3": "value4"
}
]

clear

Op.dict::clear
ArgsNone
DescriptionClears all the keys and values in the dictionary.

Example Usage

walker init{
_dict = {"key1":"value1", "key2":"value2", "key3":"value3"};
report _dict.dict::clear;
}

Expected Output

"report": [
null
]