any_vector#

swordfish.any_vector(data: Any = None) AnyVector#
swordfish.any_vector(*, size: int = 0, capacity: int = 1, default: Any = None) AnyVector

Creates a Swordfish AnyVector from a Python object or initializes one with specified size, capacity, and default value.

There are two modes of initialization:

  • If data is provided, it converts the given Python object into an AnyVector.

  • If data is not provided, a new AnyVector is created with the specified size, capacity, and default value.

Parameters:
  • data (Any, optional) – The input data to initialize the AnyVector. Defaults to None.

  • size (int, optional) – The number of elements in the AnyVector (used when data is None). Defaults to 0.

  • capacity (int, optional) – The initial capacity of the AnyVector (used when data is None). Defaults to 1.

  • default (Any, optional) – The value to fill the AnyVector (used when data is None). Defaults to None.

Returns:

A Swordfish AnyVector initialized based on the provided arguments.

Return type:

AnyVector

Examples

Creating an AnyVector from existing data:
>>> import swordfish as sf
>>> x = sf.any_vector([1, 2, 3])
>>> x
AnyVector((1,2,3))
Creating an empty AnyVector with specific size, capacity, and default value:
>>> y = sf.any_vector(size=5, capacity=10, default=3)
>>> y
AnyVector((3,3,3,3,3))