lists Flashcards
list_name.append(x)
add item to the end of the list
list_name[x]
access value at index x
list_name[x] = y
assign y value to index x
list_name.insert(x, y)
insert value y at index x
del list_name[x]
delete value at index x
list_name.pop() or list_name.pop(x)
remove an item from the end of the list
list_name.remove(x)
remove the first occurrence an item by value instead of by index
list_name.sort()
sort items in a list permanently
list_name.sort(reverse=True)
reverse the sort order
list_name.sorted()
lets you display your list in a particular order but doesn’t affect the actual order of the list
list_name.reverse()
reverse order of items in list
len(list)
returns length (number of items) in the list
list_name[-1]
access last item in list, even if list size has changed
list(range(x,y))
create a list of numbers
list[x:y]
take a slice from a list between index x and y
list[:x]
slice from beginning of list to x
list[x:]
slice from x to end of the list
list[-x:]
slice from end of list to x
new_list = list[:]
make a copy of a list
tuple
an immutable list. The name tuple comes from ‘quintuple’, ‘sextuple’, etc.