list()

Initializes a list of values using a list-expression

Synopsis

list(expression-list)

Description

The list() function returns a list containing the values represented by a given set of expressions. Each expression must evaluate to a numeric value or a list. list expressions are flattened into the larger single list.

Parameters

expressions

A comma-separated list of expressions or list expressions to assign to the list.

Returns

The list consisting of the given values, flattened into a single list.

Examples

This first example initialize a global list Primes to the first 10 prime numbers.

global_list  Primes
Primes = list(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)

In this second example, each agent has a list-variable that is initialized to that agent’s ID number, age (as an integer), sex (1 = M, 0 = F), and race code as defined in synthetic population.

personal_list my_attribute_list
my_attribute_list = list(id, age, sex, race)

In this final example, a new list is built from an existing list.

old_list = list(1, 2, 3)
new_list = list(10, old_list, 20, 30)

After this code, the list new_list will contain the list (10, 1, 2, 3, 20, 30).

Errors

It is an error if a value is not a numeric expression.

See Also

select()