Macaulay2 » Documentation
Packages » Python :: setitem
next | previous | forward | backward | up | index | toc

setitem -- set elements of mutable python sequences

Synopsis

Description

You may set elements of mutable python sequences using setitem or the shortcut _. This is equivalent to square brackets ([]) in Python. For example, this works for lists.

i1 : x = pythonValue "[1,2,3,4]"

o1 = [1, 2, 3, 4]

o1 : PythonObject of class list
i2 : setitem(x, 0, 5)
i3 : x

o3 = [5, 2, 3, 4]

o3 : PythonObject of class list

It also works for dictionaries.

i4 : x = pythonValue "{'spam':1,'eggs':2}"

o4 = {'spam': 1, 'eggs': 2}

o4 : PythonObject of class dict
i5 : x_"ham" = 3
i6 : x

o6 = {'spam': 1, 'eggs': 2, 'ham': 3}

o6 : PythonObject of class dict

Ways to use setitem :

For the programmer

The object setitem is a method function.