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.

参数:
  • 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.

返回:

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

返回类型:

Dictionary

to_dict()#

Converts the Dictionary to a Python dict.

返回:

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.

返回类型:

dict

keys()#

Retrieves the keys of the Dictionary.

返回:

The retrieved dictionary keys.

返回类型:

Constant

values()#

Retrieves the values of the Dictionary.

返回:

The retrieved dictionary values.

返回类型:

Constant

items()#

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

返回:

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

返回类型:

DictionaryItems