Chapter 7: Lists and Dictionaires Flashcards
container
a construct used to group related values together and contains references to other objects instead of data
Ex. A list
list
a container with brackets: []
contains elements
Are Mutable/ Changeable
element
a list item
index
a position inside of a list
method
adds or removes elements to/ from a list
Ex: .append()
.pop()
.remove()
.append()
list method is used to add new elements to a list.
.pop()
A list method that removes elements from a list
.remove()
A list method that removes elements from a list
len(list)
Find the length of the list
list1 + list2
Produce a new list by concatenating list2 to the end of list1
min(list)
Find the element in list with the smallest value. All elements must be of the same type
max(list)
Find the element in list with the largest value. All elements must be of the same type.
sum(list)
Find the sum of all elements of a list (numbers only)
list.index(val)
Find the index of the first element in list whose value matches val.
list.count(val)
Count the number of occurrences of the value val in list.
set()
an unordered collection of unique elements
Any repeats will only occur once
Are mutable/ changeable
Must enter a list; MUST HAVE BRACKETS!
set_literal = {}
Another way of writing a set
Has CURLY Brackets
set1.update(set2)
Adds the elements in set2 to set1.
set.clear()
Clears all elements from the set
set.intersection(set_a, set_b, set_c…)
Returns a new set containing only the elements in common between set and all provided sets.
set.union(set_a, set_b, set_c…)
Returns a new set containing all of the unique elements in all sets.
set.difference(set_a, set_b, set_c…)
Returns a set containing only the elements of set that are not found in any of the provided sets.
set_a.symmetric_difference(set_b)
Returns a set containing only elements that appear in exactly one of set_a or set_b