Exam 1 Flashcards

1
Q

What variables are mutable?

A

Lists, dictionaries and sets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What function converts a Unicode character to its integer representation?

A

ord()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What function takes the integer representing a Unicode character and returns the character itself?

A

chr()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you add a value to the end of a list?

A

list.append(value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you remove an item from a given index in a list?

A

list.pop( i )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you remove an item who’s value is “abc” from a given list?

A

list.remove(“abc”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function returns the length of a list?

A

len(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you concatenate a given list “list1” to the end of another list “list2”?

A

list1 + list2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you find the smallest value element of a given list?

And how do you find the largest?

A

min(list)

max(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you find the sum of all elements in a list? (Numbers only)

A

sum(list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you count the number of instances of a given value that are in a list?

A

list.count(value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you find the index of (the first instance of) a given value in a list?

A

list.index(value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you concatenate the list “feb_temps” to the end of “jan_temps”?

A

jan_temps + feb_temps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a tuple?

A

It stores a collection of data like a list, but is immutable.

It generally uses parenthesis ( ) instead of brackets [ ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a named tuple and how is it formatted?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you add a list/grouping of objects to a list?

A

list.extend[vals]

17
Q

How do you INSERT an object at a specific index?

A

x is inserted before the index ‘i’

list.insert(i, x)

18
Q

How do you sort the items of a list?

A

list.sort()

19
Q

How do you delete an object at a specific index from a list?

A

del my_list[ i ]

20
Q

How do you get a new list containing values from a specific range of indices of an existing list?

A

creates list new_list with values from indices 1-3 of og_list

new_list = og_list[1:3]

21
Q

What is the format for making a copy of a list?

A

including a colon with NO index range just copies the entire list

new_list = old_list[ : ]

22
Q

How do you check if a variable “x” is in a given list of values “my_list”?

A

true if it is the list, false otherwise.

if x in my_list: