NEW
Font size
WorksheetsChapter 10 Review
Total questions: 25
Worksheet time: 13mins
What will run when the following code is executed?
my_dict = {
'name': 'Nick',
'age': 31,
'occupation': 'Dentist',
}
for key in my_dict:
print key, my_dict[key]
"age 31"
"name Nick"
"occupation Dentist"
{age 31}
{name Nick}
{occupation Dentist}
age 31
name Nick
occupation Dentist
(age 31)
(name Nick)
(occupation Dentist)
What will run when the following code is executed?
my_dict = {
'name': 'Nick',
'age': 31,
'occupation': 'Dentist',
}
print my_dict.values()
[31, 'Nick', 'Dentist']
"31, 'Nick', 'Dentist'
{31, 'Nick', 'Dentist'}
31, Nick, Dentist
What will run when the following code is executed?
my_dict = {
'name': 'Nick',
'age': 31,
'occupation': 'Dentist',
}
print my_dict.keys()
age, name, occupation
['age', 'name', 'occupation']
{age, name, occupation}
*age, name, occupation*
What will run when the following code is executed?
evens_to_18 = [i for i in range(19) if i % 2 == 0]
print evens_to_18
0,2,4,6,8,10,12,14,16,18
{0,2,4,6,8,10,12,14,16,18}
[0,2,4,6,8,10,12,14,16,18]
"0,2,4,6,8,10,12,14,16,18"
What will run when the following code is executed?
evens_to_18 = [i for i in range(19) if i % 4 == 0]
print evens_to_18
0,4,8,12,16
*0,4,8,12,16*
{0,4,8,12,16}
[0,4,8,12,16]
What will run when the following code is executed?
even_squares = [x ** 2 for x in range(1, 8) if x % 2 == 0]
print even_squares
4,16,36
{4,16,36}
[4,16,36]
*4,16,36*
What will run when the following code is executed?
doubles_by_3 = [x * 2 for x in range(1, 12) if (x * 2) % 3 == 0]
print doubles_by_3
[6,12,18]
6,12,18
{6,12,18}
*6,12,18*
What will run when the following code is executed?
l = [i ** 2 for i in range(1, 11)]
print l [2:9:2]
{9,25,49,81}
[9,25,49,81]
9,25,49,81
*9,25,49,81*
List slicing includes the following:
[start:end:stride]
{start:end:stride}
start:end:stride
"start": "end": "stride"
When list slicing:
start is "inclusive"
True
False
When list slicing:
end is "exclusive"
True
False
When list slicing:
stride describes the syntax of the function
True
False
What will run when the following code is executed?
my_list = range(1, 11)
print my_list[::2]
1, 3, 5, 7, 9
[1, 3, 5, 7, 9]
{1, 3, 5, 7, 9}
*1, 3, 5, 7, 9*
What will run when the following code is executed?
my_list = range(1, 16)
print my_list[::2]
{1, 3, 5, 7, 9, 11, 13, 15}
(1, 3, 5, 7, 9, 11, 13, 15)
[1, 3, 5, 7, 9, 11, 13, 15]
"1, 3, 5, 7, 9, 11, 13, 15"
What will run when the following code is executed?
my_list = range(1, 11)
backwards = my_list[::-1]
print backwards
10, 9, 8, 7, 6, 5, 4, 3, 2, 1
(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
*10, 9, 8, 7, 6, 5, 4, 3, 2, 1*
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
What will run when the following code is executed?
to_one_hundred = range(101)
backwards_by_tens = to_one_hundred[::-10]
print backwards_by_tens
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0]
100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
What will run when the following code is executed?
to_one_hundred = range(101)
backwards_by_twenty = to_one_hundred[::-20]
print backwards_by_twenty
100, 80, 60, 40, 20, 0
[0, 20, 40, 60, 80, 100]
[100, 80, 60, 40, 20, 0]
0, 20, 40, 60, 80, 100
What will run when the following code is executed?
odds = to_21 [::2]
print odds
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21
[21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]
21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1
What will run when the following code is executed?
my_list = range(16)
print filter(lambda x: x % 3 == 0, my_list)
[0, 3, 6, 9, 12, 15]
0, 3, 6, 9, 12, 15
{0, 3, 6, 9, 12, 15}
"0, 3, 6, 9, 12, 15"
What will run when the following code is executed?
my_list = range(16)
print filter(lambda x: x % 5 == 0, my_list)
{0,5,10,15}
0,5,10,15
(0,5,10,15)
[0,5,10,15]
What will run when the following code is executed?
fives = [x for x in range(1, 16) if x % 3 == 0 or x % 5 == 0]
print fives
[0,5,10,15]
{5,10,15}
*3, 5, 6, 9, 10, 12, 15*
[5,10,15]
Which method returns the a list of the dictionary's keys?
.keys[ ]
.keys( )
.keys { }
None of these options
Which of the following methods returns a list of the dictionary's values?
.values( )
.values[ ]
.values" "
None of these options
Which method returns an array of tuples?
.items[ ]
.items( )
.items{ }
None of these options
List slicing does not allow the user to access elements of a list in a specific manner.
True
False
