PLP - Python Learning Program Curriculum - v2
PLP - Python Learning Program Curriculum - v2
P2. Merge 2 objects with any depth (including contained dictionaries, lists, sets, strings, integers,
floats). Type mismatches should yield a tuple with the two elements. Examples:
a = {'x': [1,2,3], 'y': 1, 'z': set([1,2,3]), 'w': 'qweqwe', 't': {'a': [1, 2]}, 'm': [1]}
b = {'x': [4,5,6], 'y': 4, 'z': set([4,2,3]), 'w': 'asdf', 't': {'a': [3, 2]}, 'm': "wer"}
Expected result:
{'x': [1,2,3,4,5,6], 'y': 5, 'z': set([1,2,3,4]), 'w': 'qweqweasdf', 't': {'a': [1, 2, 3,
2]}, 'm': ([1], "wer")}
P3. Given a file containing a list of dictionaries implement a sorting algorithm (of your choosing)
that will sort the list based on the dictionary keys. The dictionary keys will contain alphabetic
characters while the values will be integers. The rule for comparing dictionaries between them is:
if the value of the dictionary with the lowest alphabetic key is lower than the value of the
other dictionary with the lowest alphabetic key, then the first dictionary is smaller than the
second.
if the two values specified in the previous rule are equal reapply the algorithm ignoring the
current key.
The input is a file containing the list of dictionaries. Each dictionary key value is specified on the
same line in the form <key> <whitespace> <value>. Each list item is split by an empty row. The
output is a file containing a list of integers specifying the dictionary list in sorted order. Each integer
identifies a dictionary in the order they were received in the input file.
1
Phase 2 (intermediate) – instructors: Andrei M., Paul O.
A. Topics and reading materials
P2. Create an automated card dealer for a Texas Hold’em application. It should be able to
handle Deck objects, consisting of Cards. Cards can be added or removed from Decks, and Decks can
be shuffled and sorted. When dealing cards, each Player receives a Hand consisting of 2 Cards. After
all cards are dealt, the Dealer should draw the table Hand of 5 Cards"
P3. Write a function decorator that tracks how long the execution of the wrapped function took.
The decorator will log slow function calls including details about the execution time and function
name. The decorator should take an optional threshold argument.
Examples:
@time_slow
def myfast():
pass
@time_slow(threshold=0.05)
def myfast():
pass
2
Phase 3 (advanced) – instructors: Ionel M., Ion S.
A. Topics and reading materials
Iterators vs. Generators
PyIterGen.pdf
itertools
o http://docs.python.org/library/itertools.html
functools
o http://docs.python.org/library/functools.html
Metaclasses
o http://docs.python.org/reference/datamodel.html#object.__new__
o http://docs.python.org/reference/datamodel.html#customizing-class-creation
o http://www.cafepy.com/article/python_types_and_objects/ - Newstyle classes,
type and metaclass intro
o http://www.cafepy.com/article/python_attributes_and_methods / - Attributes,
descriptors, resolution order (multi inheritance)
o http://www.vrplumber.com/programming/metaclasses.pdf
o http://www.vrplumber.com/programming/mcsamples.tar.gz - Code samples for the
presentation above
o http://cleverdevil.org/computing/78/metaclasses-demystified
Lambda expressions
o http://diveintopython.net/power_of_introspection/lambda_functions.html
Class decorators
o http://www.python.org/dev/peps/pep-3129/ - PEP describing the class decorators
o http://wiki.python.org/moin/PythonDecoratorLibrary - a comprehensive list of
decorator examples
Debugging
o (http://www.doughellmann.com/PyMOTW/pdb/)
o http://ipython.org/documentation.html
P2. Write a generator that returns all the subsets of a given set. Example:
Input: set([1, 2, 3])
Output: set([1, 2, 3]), set([2, 3]), set([1, 3]), set([3]), set([1,
2]), set([2]), set([1]), set([])
3
P3. Implement singleton pattern using meta classes
P4. Review the Django implementation of Models which uses metaclasses extensively and
identify alternative ways to implement the same functionality (or similar) using other techniques
and paradigms. If you think the current solution is the best approach, please specify the reasons
behind this conclusion.