Chapter 7 Flashcards
What does list.append() do?
Add the contents of the brackets to the end of the list as one element
What does list.extend() do?
Add a list to the end of the list
What does list[x:x] = [1,2,3] do?
Add the list [1,2,3] at index x, move every value past index x down by one (including index x)
what does list[x] = 1 do?
replace list[x] current value with 1
What does list.insert(index,value) do?
inserts the value in list[index] while shuffling everything down one index, nothing is overwritten.
- Though .insert() does nest its contents, it doesn’t split it into separate indices
- e.g. list = [1,2,5,6]
- list.instert(2, [3,4])
- list = [1,2, [3,4], 5, 6]
What does list.insert(len(list),val) do?
list.append(val)
What is the output for x[::-1]
x = [1, 2, 3, 4, 5, 6]
[6, 5, 4, 3, 2, 1]
How do you splice a list?
list[start : end : index step]
start included
end not included
What does list[:] output?
The complete list
What does list[::-2] output?
Every other element of the list, counting backwards
What does list[-1] output?
Last character of the list
What does list[-1:] output?
The last character of a list
What does list.pop(index) do?
Deletes the value at the index in the list, can also be assigned to a variable while removing it from a list
What does list.sort() do?
Sort the list in ascending order
What does list.index(x) do?
returns the earliest index of value x