Dictionary#

class swordfish._swordfishcpp.Dictionary#

Represents a container type that holds unique key-value pairs.

A mapping structure similar to Python’s dict, but with Swordfish-specific type handling and conversion capabilities.

classmethod from_dict(data, *, key_type=None, val_type=None)#

Constructs a Dictionary object from a Python dict.

Parameters:
  • data (dict) – A Python dict containing the key-value pairs to be included in the new Dictionary.

  • key_type (DataType, optional) – An enumeration value from the DataType enum, specifying the target data type for the Dictionary keys. If None, the type will be inferred from the input dict’s keys. Defaults to None.

  • val_type (DataType, optional) – An enumeration value from the DataType enum, specifying the target data type for the Dictionary values. If None, the type will be inferred from the input dict’s values. Defaults to None.

Returns:

A new Dictionary object containing the key-value pairs from the input Python dict.

Return type:

Dictionary

to_dict()#

Converts the Dictionary to a Python dict.

Returns:

A Python dict representing this Dictionary object. If the Dictionary’s value type is ‘Any’: keys are converted to their corresponding Python types, values are Constant objects. Otherwise, both keys and values are converted to their corresponding Python types.

Return type:

dict

keys()#

Retrieves the keys of the Dictionary.

Returns:

The retrieved dictionary keys.

Return type:

Constant

values()#

Retrieves the values of the Dictionary.

Returns:

The retrieved dictionary values.

Return type:

Constant

items()#

Retrieves an iterator over the Dictionary’s key-value pairs.

Returns:

An iterable object that yields key-value pairs from the Dictionary.

Return type:

DictionaryItems