add-value-to-dictionary

Description

add-value-to-dictionary adaptor is used to add a key-value pair to an existing dictionary, or to a new dictionary if the dictionary input is not specified.

By default, the adaptor will update the value if the key is already existing in the input dictionary. This can be changed by setting overwrite input to False.

Inputs

dictionary Type: dictionary Required: No The dictionary to which the value will be added. If unspecified, the value will be added to a new dictionary.

key Type: text Required: Yes The key to be added to the dictionary.

value Type: text Required: Yes The value to be added to the dictionary.

overwrite Type: boolean Required: No Whether to overwrite the value if the specified key already exists in the dictionary. If unspecified, defaults to True.

Outputs

dictionary Type: dictionary A dictionary containing the added value.

Examples

Example 1: Default behaviour.

Inputs:

dictionary:

KEY
VALUE

GB

United Kingdom

TR

Turkey

key: US value: United States

Outputs:

dictionary:

KEY
VALUE

GB

United Kingdom

TR

Turkey

US

United States

-> Added a new key-value pair { US: "United States" } to an existing dictionary.

Example 2: Adding a key-value pair to a new dictionary.

Inputs:

key: GB

value: United Kingdom

Outputs:

dictionary:

KEY
VALUE

GB

United Kingdom

-> Added a key-value pair { GB: "United Kingdom" } to a new dictionary.

Example 3: Updating an existing key in a dictionary.

Inputs:

dictionary:

KEY
VALUE

GB

United Kingdom

TR

Turkey

key: TR

value: Turkiye

Outputs:

dictionary:

KEY
VALUE

GB

United Kingdom

TR

Turkiye

-> Updated an existing dictionary with the key-value pair { TR: "Turkiye" }.

Use Cases

  • Represent associative data where there is a clear relationship between keys and values, such as mapping country codes to country names.

  • Facilitate language translation by using key-value pairs where keys represent phrases or terms in one language, and values represent their translations in another language.

Last updated