Append

There are many list functions that mutate rather than recreate a list. The first of these is the list append function. This operation adds an element to the end of the list (this is different from append in Snap). This function cannot be called alone. It must be called using a list as shown below.


>>> idiom = ["peas", "in", "a"]
>>> idiom.append("pod")
                    

>>> idiom 
["peas", "in", "a", "pod"]
                    

Note: idiom.append("pod") does not return the modified list.

Insert

However, if the additon of an item to a list requires that the item be placed at a specific location, insert can be used to place an element at a desired index. The first argument is the index of the insert position, the second argument is the element itself.


>>> remark = ["break", "leg"]
>>> remark.insert(1, "a")
                    

>>> remark
["break", "a", "leg"]
                    

Pop

Finally, use pop(i) to remove the item at position i in the list. If no argument is given (e.g. crime.pop()) will remove the last item of the list.


>>> crime = ["dont", "steal", "the", "cookie"]
>>> crime.pop(3)
'cookie'
                    

>>> crime
["dont", "steal", "the"]
                    

Note: in snap the delete block does not return the list item that is deleted, while Python's .pop() function does return the item that it removes.