Data Structure

Lists, tuples, dictionaries, and sets are the most fundamental data structures in Python. To better adapt to the DolphinDB runtime environment, Python Parser supports these basic structures and related operations, such as defining DolphinDB objects within Python's data structures and converting Python objects into DolphinDB objects.

Operations on Python Parser Objects

Syntax

Usage

type(obj) Return the type of an object
dir(obj) Return the methods available for an object
help(obj) Return the documentation of an object
id(obj) Return a unique id (object's address) of an object
str(obj) Convert an object into a string
len(obj) Return the length of an object
hash(obj) Return the hash value of an object
range(stop) or range(start, stop[, step]) Return a sequence of numbers (an iterable object)
iter(iterable) Return an iterator

Comparison Between the Data Structures of DolphinDB and Python Parser

Functions sharing the same name in DolphinDB and Python Parser are parsed as Python's built-in functions. To use DolphinDB's built-in functions, it is necessary to import the dolphindb package using the script import dolphindb as ddb. The following table compares the data structures of DolphinDB and Python Parser:

DolphinDB

Python Parser

scalar Consistent with the scalar in DolphinDB
regular vector

list.toddb()

(list must be strongly typed)

any vector list.toddb() or tuple.toddb()
HUGE vector Created with bigarray (DolphinDB's built-in function)
array vector Created with arrayVector (DolphinDB's built-in function)
subarray Created with subarray (DolphinDB's built-in function)
pair ( : ) Created with pair (DolphinDB's built-in function)
matrix / cast( $ ) Created with matrix (DolphinDB's built-in function)
set set.toddb() / ddb.set
dict / {key: value} dict.toddb() / ddb.dict
table Created with table (DolphinDB's built-in function)

Note: In DolphinDB, VOID vectors cannot be created with [NULL, NULL]. In Python Parser, however, VOID vectors of ANY type can be created with [None, None].toddb().