Tuesday, July 24, 2018

Python Data Structures - Chapter 10 Quiz


Question 1
1
point

1. Question 1

What is the difference between a Python tuple and Python list?
Question 2
1
point

2. Question 2

Which of the following methods work both in Python lists and Python tuples?
Question 3
1
point

3. Question 3

What will end up in the variable y after this code is executed?
1
x , y = 3, 4
Question 4
1
point

4. Question 4

In the following Python code, what will end up in the variable y?
1
2
x = { 'chuck' : 1 , 'fred' : 42, 'jan': 100}
y = x.items()
Question 5
1
point

5. Question 5

Which of the following tuples is greater than x in the following Python sequence?
1
2
3
x = (5, 1, 3)
if ??? > x :
...
Question 6
1
point

6. Question 6

What does the following Python code accomplish, assuming the c is a non-empty dictionary?
1
2
3
tmp = list()
for k, v in c.items() :
tmp.append( (v, k) )
Question 7
1
point

7. Question 7

If the variable data is a Python list, how do we sort it in reverse order?
Question 8
1
point

8. Question 8

Using the following tuple, how would you print 'Wed'?
1
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
Question 9
1
point

9. Question 9

In the following Python loop, why are there two iteration variables (k and v)?
1
2
3
c = {'a':10, 'b':1, 'c':22}
for k, v in c.items() :
...
Question 10
1
point

10. Question 10

Given that Python lists and Python tuples are quite similar - when might you prefer to use a tuple over a list?

1 comment: