$30
Tiny Practical Final
Time limit: 20 minutes
Question 1
(10 fake marks) Suppose the file sample_imports.txt contains a list of Python import
statements like this:
import time
import random
import turtle
import doctest
import turtle
import time
For simplicity, assume that every line is an import statement formatted as in the example. There
are no blank lines or extra spaces around the words.
Write a program that reads sample_imports.txt and prints the imports in sorted order, and with
any duplicates removed. For example, the above file gets printed like this:
import doctest
import random
import time
import turtle
Of course, sample_imports.txt should work with any file of imports, not just the one in the example.
Question 2
(10 fake marks) Write a function called string_sort(str_list) that takes a list of strings as
input and returns a copy of str_list sorted by length, from smallest to biggest. Strings of the
same length should be sorted alphabetically. For example:
>>> string_sort(['dog', 'or', 'a', 'cat'])
['a', 'or', 'cat', 'dog']