1/37
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Container
an object that groups related objects together
Mutable
value can be changed after it has been created (EX. lists, dictionaries)
Immutable
value can not be changed after it has been created (EX. numbers, strings, tuples)
List
a mutable container, meaning the size of this can grow or shrink and elements within can change
Items in a list are called…
elements
Code for creating a list
list()
Another way to create a list (EX. put 1, 2, & 3 into my_list)
my_list = [1, 2, 3]
Index
a zero-based integer matching to a specific position in the list’s sequence of elements
Code for indexing in a list (EX. trying to find the 2nd item in my_list)
my_list[1]
A list’s index must be an _______ type
integer
In-place modifications
the ability to grow or shrink a list
Code for changing the value of element at index i in my_list
my_list[i] = x
Lists are used to help ______ the number of variables created
reduce
Methods
instruct an object to perform some action
my_list.append(‘m’)
adds the value ‘m’ to the end of the list
my_list.pop(1)
removes the element at index 1
my_list.remove(‘m’)
removes the first element whose value is ‘m’
Sequence-type functions and methods
built-in functions and methods that operate on sequences like lists and strings
max(my_list)
finds the element in the list with the largest value (even letters have values)
min(my_list)
finds the element in the list with the smallest value
sum(my_list)
finds the total of all elements of a list (numbers only)
my_list.index(‘m’)
finds the index of the first element that matches the value ‘m’
my_list.count(‘m’)
finds how many times the value ‘m’ is in the list
my_list.extend([4, 12])
adds all items (4 & 12) to the list
my_list = [3, 5]
my_list.insert(3, 8)
inserts value 8 into position before 3
my_list = [8, 3, 5]
my_list = [4, 3, 7, 5]
my_list.sort()
puts the elements in order
my_list = [3, 4, 5, 7]
my_list.reverse()
reverses the order of elements in the list
Slice notation
to read multiple elements from a list, creating a new list that contains only the desired elements (EX. my_list[0:2])
Negative indices can be used to count _________ from the end of the list (my_list[0,-1])
backwards
Stride
indicates how many elements are skipped between extracted items in the list (EX. my_list[0:5:2])
List nesting
embedding a list inside another list
EX. my_list = [3, [5, 13], 8]
Programmers can access all elements of nested lists by using…
nested for loops
split()
divides a string into a list of tokens
Token
a substring that forms a part of a larger string
Separator
a character that indicates where to split the string into tokens (EX. string.split(‘#’))
join()
performs the inverse operation of split to create a single string
Parameters
variables listed inside parentheses in a function
Arguments
actual values passed to a function when called