NEW
Font size
WorksheetsUnit 9
Total questions: 10
Worksheet time: 7mins
Given the following list,
my_list = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11] ]
Which line of code would print the number ‘5’ to the screen?
print(my_list[1])
print(my_list[1:2])
print(my_list[1][2])
print(my_list[2][3])
What kind of data structure is user_data in the following declaration?
user_data = {"name": "TJ", "age":24, "user_name":"artLover123"}
Tuple
List
Dictionary
2D List
What is the output of this program?
12
45
1
3
7
2
5
8
3
12
3
5
45
7
8
1
2
3
12
3
5
3
2
1
8
7
45
5
3
12
Which of the following code snippets will create this 2D list?
board = [1, 2, 3] + [4, 5, 6] + [7, 8, 9]
board = [1, 2, 3]
board.append([4, 5, 6])
board.append([7, 8, 9])
board = [1, 2, 3, 4, 5, 6, 7, 8, 9]
board = [] board.append([1, 2, 3]) board.append([4, 5, 6]) board.append([7, 8, 9])
Which of the following list comprehensions will create the same list as the for loop below?
my_list = [i for i in range(6)]
my_list = [i*2 for i in range(6)]
my_list = [i for i*2 in range(6)]
This cannot be done using a list comprehension statement.
What does “packing” refer to in Python?
Creating a list
Initializing variables using values from a list
Storing multiple variables’ values by putting them in a collection, like a list or tuple
Cramming as many commands as possible onto a single line
What does “unpacking” refer to in Python?
Creating a list
Initializing multiple variables at a time using a collection of values
Storing multiple variables’ values by putting them in a collection, like a list or tuple
Cramming as many commands as possible onto a single line
Which of the following assignment statements is equivalent to the following code snippet?
red, blue, green = "BLUE", "GREEN", "RED"
red = "RED"
blue = "BLUE" green = "GREEN"
red = "BLUE"
blue = "GREEN" green = "RED"
red = ["BLUE", "GREEN", "RED"]
blue = ["BLUE", "GREEN", "RED"] green = ["BLUE", "GREEN", "RED"]
red = "BLUE"
blue = "BLUE" green = "BLUE"
A dictionary maps:
strings to strings
strings to numbers
indices to elements
keys to values
Use the following definitions of foods and groceries.
foods = ["apples", "eel", "kale"]
groceries = ["apples", "eel", "kale"]
Which of the following statements would evaluate to True about foods and groceries?
I. foods == groceries
II. foods is groceries
I only
II only
Both I and II
Neither I nor II
