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)