Skip to content

erase

Syntax

erase(variable_name, index_or_key)

Parameters

variable_name
The name of a list, table, or list_table variable from which an element/key-value pair is to be removed.
index_or_key
An expression that evaluates to a possible key in the table or list table, or the index of an element in the list.

Returns

Returns the value of the element that was erased.

Can be used without assigning a variable to a its return value.

Description

Removes a key-value pair from a table or a list_table variable, or removes an element from a list.

If the first parameter is a list, this action removes an element from the list at the supplied index parameter. Note that lists are 0-indexed.

If the first parameter is a table or list table, this actions removes the key-value with the specified key from the specified table or list_table. If the key does not exist, an error occurs.

This action returns the value that was removed, though it can be called without assigning a variable to its return value.

An error occurs if the index is out of bounds.

Examples

    # Assuming "my_shared_list" is defined as list variable with values
    # equal to list(1, 2, 3, 4, 5)

    print("Shared list before removing elements: ", my_shared_list)
    # Prints: "Shared list before removing elements: 1 2 3 4 5"

    print("Removing element 0 with value: ", erase(my_shared_list, 0))
    # Prints: "Removing element 0 with value: 1"

    print("Shared list after executing erase: ", my_shared_list)
    # Prints: "Shared list after executing erase: 2 3 4 5"

    erase(my_shared_list, 3)
    print("Shared list after executing erase: ", my_shared_list)
    # Prints: "Shared list after executing erase: 2 3 4"

See Also