Exam 1 Flashcards
What variables are mutable?
Lists, dictionaries and sets.
What function converts a Unicode character to its integer representation?
ord()
What function takes the integer representing a Unicode character and returns the character itself?
chr()
How do you add a value to the end of a list?
list.append(value)
How do you remove an item from a given index in a list?
list.pop( i )
How do you remove an item who’s value is “abc” from a given list?
list.remove(“abc”)
What function returns the length of a list?
len(list)
How do you concatenate a given list “list1” to the end of another list “list2”?
list1 + list2
How do you find the smallest value element of a given list?
And how do you find the largest?
min(list)
max(list)
How do you find the sum of all elements in a list? (Numbers only)
sum(list)
How do you count the number of instances of a given value that are in a list?
list.count(value)
How do you find the index of (the first instance of) a given value in a list?
list.index(value)
How would you concatenate the list “feb_temps” to the end of “jan_temps”?
jan_temps + feb_temps
What is a tuple?
It stores a collection of data like a list, but is immutable.
It generally uses parenthesis ( ) instead of brackets [ ]
What is a named tuple and how is it formatted?
example instance:
It is a container that defines a new simple data type consisting of named attributes.
Car = namedtuple(‘Car’, [‘make’, ‘model’, ‘price’]
chevy_impala = Car(‘Chevrolet’, ‘Impala’, 37495)
How do you add a list/grouping of objects to a list?
list.extend[vals]
How do you INSERT an object at a specific index?
x is inserted before the index ‘i’
list.insert(i, x)
How do you sort the items of a list?
list.sort()
How do you delete an object at a specific index from a list?
del my_list[ i ]
How do you get a new list containing values from a specific range of indices of an existing list?
creates list new_list with values from indices 1-3 of og_list
new_list = og_list[1:3]
What is the format for making a copy of a list?
including a colon with NO index range just copies the entire list
new_list = old_list[ : ]
How do you check if a variable “x” is in a given list of values “my_list”?
true if it is the list, false otherwise.
if x in my_list: