Added chapters and list of exercises
This commit is contained in:
commit
1c106d776c
4
CH_01_getting_started/README.rst
Normal file
4
CH_01_getting_started/README.rst
Normal file
@ -0,0 +1,4 @@
|
||||
Chapter 1 - getting started
|
||||
=======================================================================================================================
|
||||
|
||||
Chapter 1 has no exercises.
|
||||
0
CH_01_getting_started/__init__.py
Normal file
0
CH_01_getting_started/__init__.py
Normal file
8
CH_02_interactive_python/README.rst
Normal file
8
CH_02_interactive_python/README.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Chapter 2 - interactive python
|
||||
=======================================================================================================================
|
||||
|
||||
1. The `rlcompleter` enhancement we created currently only handles dictionaries. Try and extend the code so it supports lists, strings, and tuples as well.
|
||||
2. Add colors to the completer (hint: use `colorama` for the coloring).
|
||||
3. Instead of manually completing using our own object introspection, try and use the `jedi` library for autocompletion, which does static code analysis.
|
||||
4. Try to create a `Hello` `<ipywidget>` so the name of the person can be edited through a notebook without code changes.
|
||||
5. Try and create a script that will look for a given pattern through all of your previous ipython sessions.
|
||||
0
CH_02_interactive_python/__init__.py
Normal file
0
CH_02_interactive_python/__init__.py
Normal file
4
CH_03_pythonic_syntax/README.rst
Normal file
4
CH_03_pythonic_syntax/README.rst
Normal file
@ -0,0 +1,4 @@
|
||||
Chapter 3 - pythonic syntax
|
||||
=======================================================================================================================
|
||||
|
||||
Chapter 3 has no exercises.
|
||||
0
CH_03_pythonic_syntax/__init__.py
Normal file
0
CH_03_pythonic_syntax/__init__.py
Normal file
6
CH_04_design_patterns/README.rst
Normal file
6
CH_04_design_patterns/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 4 - design patterns
|
||||
=======================================================================================================================
|
||||
|
||||
- Create a SortedDict collection that takes a keyfunc to decide the sort order.
|
||||
- Create a SortedList collection that has O(log(n)) inserts and always returns a sorted list during each iteration.
|
||||
- Create a Borg pattern that has a state per subclass.
|
||||
0
CH_04_design_patterns/__init__.py
Normal file
0
CH_04_design_patterns/__init__.py
Normal file
6
CH_05_functional_programming/README.rst
Normal file
6
CH_05_functional_programming/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 5 - functional programming
|
||||
=======================================================================================================================
|
||||
|
||||
1. Implement the quicksort algorithm.
|
||||
2. Write a groupby function that isn’t affected by sorting.
|
||||
3. Write a groupby function that returns lists of results instead of generators.
|
||||
0
CH_05_functional_programming/__init__.py
Normal file
0
CH_05_functional_programming/__init__.py
Normal file
10
CH_06_decorators/README.rst
Normal file
10
CH_06_decorators/README.rst
Normal file
@ -0,0 +1,10 @@
|
||||
Chapter 6 - decorators
|
||||
=======================================================================================================================
|
||||
|
||||
1. Extend the `track` function to monitor execution time.
|
||||
2. Extend the `track` function with min/max/average execution time and call count.
|
||||
3. Modify the memoization function to function with unhashable types.
|
||||
4. Modify the memoization function to have a cache per function instead of a global one.
|
||||
5. Create a version of `functools.cached_property` that can be recalculated as needed.
|
||||
6. Create a single-dispatch decorator that considers all or a configurable number of arguments instead of only the first one.
|
||||
7. Enhance the `type_check` decorator to include additional checks such as requiring a number to be greater than or less than a given value.
|
||||
0
CH_06_decorators/__init__.py
Normal file
0
CH_06_decorators/__init__.py
Normal file
7
CH_07_generators_and_coroutines/README.rst
Normal file
7
CH_07_generators_and_coroutines/README.rst
Normal file
@ -0,0 +1,7 @@
|
||||
Chapter 7 - generators and coroutines
|
||||
=======================================================================================================================
|
||||
|
||||
1. Create a generator similar to `itertools.islice()` that allows for a negative step so you can execute `some_list[20:10:-1]`.
|
||||
2. Create a class that wraps a generator so it becomes sliceable by using `itertools.islice()` internally.
|
||||
3. Write a generator for the Fibonacci numbers.
|
||||
4. Write a generator that uses the sieve of Eratosthenes to generate prime numbers.
|
||||
0
CH_07_generators_and_coroutines/__init__.py
Normal file
0
CH_07_generators_and_coroutines/__init__.py
Normal file
8
CH_08_metaclasses/README.rst
Normal file
8
CH_08_metaclasses/README.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Chapter 8 - metaclasses
|
||||
=======================================================================================================================
|
||||
|
||||
1. Create a metaclass to test if attributes/methods are available.
|
||||
2. Create a metaclass to test if specific classes are inherited.
|
||||
3. Build a metaclass that wraps every method with a decorator (could be useful for logging/de- bugging purposes), something with a signature like this:
|
||||
|
||||
class SomeClass(metaclass=WrappingMeta, wrapper=some_wrapper):
|
||||
0
CH_08_metaclasses/__init__.py
Normal file
0
CH_08_metaclasses/__init__.py
Normal file
6
CH_09_documentation/README.rst
Normal file
6
CH_09_documentation/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 9 - documentation
|
||||
=======================================================================================================================
|
||||
|
||||
1. Type hint a complex `dict`
|
||||
2. Type hint nested types
|
||||
3. Type hint recursive types
|
||||
0
CH_09_documentation/__init__.py
Normal file
0
CH_09_documentation/__init__.py
Normal file
8
CH_10_testing_and_logging/README.rst
Normal file
8
CH_10_testing_and_logging/README.rst
Normal file
@ -0,0 +1,8 @@
|
||||
Chapter 10 - testing and logging
|
||||
=======================================================================================================================
|
||||
|
||||
1. Create a function that tests the doctests of a given function/class.
|
||||
2. For a greater challenge, create a function that recursively tests all doctests of every function and class in a given module.
|
||||
3. Create a `py.test` plugin that checks if all tested files have file-level documentation. Hint: use `pytest_collect_file`.
|
||||
4. Create a custom `tox` environment to run `flake8` or `mypy` on your project.
|
||||
5. Create a `LoggerAdapter` that combines multiple messages into a single message based on some task ID.
|
||||
0
CH_10_testing_and_logging/__init__.py
Normal file
0
CH_10_testing_and_logging/__init__.py
Normal file
6
CH_11_debugging/README.rst
Normal file
6
CH_11_debugging/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 11 - debugging
|
||||
=======================================================================================================================
|
||||
|
||||
1. Execute code with a timeout so you can see where your application is stalling
|
||||
2. Measure the duration of the execution
|
||||
3. Show how often that specific bit of code has been executed
|
||||
0
CH_11_debugging/__init__.py
Normal file
0
CH_11_debugging/__init__.py
Normal file
6
CH_12_performance/README.rst
Normal file
6
CH_12_performance/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 12 - performance
|
||||
=======================================================================================================================
|
||||
|
||||
1. Try to create a decorator that monitors each run of a function and warns you if the memory usage grows each run.
|
||||
2. Try to create a decorator that monitors the runtime of a function and warns you if it deviates too much from the previous run. Optionally, you could make the function generate a (running) average runtime as well.
|
||||
3. Try to create a memory manager for your classes that warns you when more than a configured number of instances remain in memory. If you never expect more than 5 instances of a certain class, you can warn the user when that number is exceeded.
|
||||
0
CH_12_performance/__init__.py
Normal file
0
CH_12_performance/__init__.py
Normal file
6
CH_13_async_io/README.rst
Normal file
6
CH_13_async_io/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 13 - async io
|
||||
=======================================================================================================================
|
||||
|
||||
1. Try to create a `asyncio` base class that automatically registers all instances for easy closing/destructuring when you are done
|
||||
2. Create an `asyncio` wrapper class for a synchronous process such as file or network operations using executors
|
||||
|
||||
0
CH_13_async_io/__init__.py
Normal file
0
CH_13_async_io/__init__.py
Normal file
10
CH_14_multithreading_and_multiprocessing/README.rst
Normal file
10
CH_14_multithreading_and_multiprocessing/README.rst
Normal file
@ -0,0 +1,10 @@
|
||||
Chapter 14 - multithreading and multiprocessing
|
||||
=======================================================================================================================
|
||||
|
||||
1. See if you can make an echo server and client as separate processes. Even though we did not cover `multiprocessing.Pipe()`, I trust you can work with it regardless. It can be created through `a, b = multiprocessing.Pipe()` and you can use it with `a.send()` or `b.send()` and `a.recv()` or `b.recv()`.
|
||||
2. Read all files in a directory and sum the size of the files by reading each file using `concurrent.futures`. If you want an extra challenge, walk through the directories recursively by letting the thread/process queue new items while running.
|
||||
3. Read all files in a directory and sum the size of the files by reading each file using `threading` or `multiprocessing`
|
||||
4. As above, but walk through the directories recursively by letting the thread/process queue new items while running.
|
||||
5. Create a pool of workers that keeps waiting for items to be queued through `multiprocessing.Queue()`.
|
||||
6. Convert the pool above to a safe RPC (remote procedure call) type operation.
|
||||
7. Apply your functional programming skills and calculate something in a parallel way. Perhaps parallel sorting?
|
||||
5
CH_15_scientific_python/README.rst
Normal file
5
CH_15_scientific_python/README.rst
Normal file
@ -0,0 +1,5 @@
|
||||
Chapter 15 - scientific python
|
||||
=======================================================================================================================
|
||||
|
||||
1. Create a datashader plot.
|
||||
2. Make the datashater plot interactive using a Jupyter notebook.
|
||||
0
CH_15_scientific_python/__init__.py
Normal file
0
CH_15_scientific_python/__init__.py
Normal file
4
CH_16_machine_learning/README.rst
Normal file
4
CH_16_machine_learning/README.rst
Normal file
@ -0,0 +1,4 @@
|
||||
Chapter 16 - machine learning
|
||||
=======================================================================================================================
|
||||
|
||||
1. Extract data or information from this chapter’s summary by applying one of the NLP algorithms.
|
||||
0
CH_16_machine_learning/__init__.py
Normal file
0
CH_16_machine_learning/__init__.py
Normal file
5
CH_17_c_and_cpp_extensions/README.rst
Normal file
5
CH_17_c_and_cpp_extensions/README.rst
Normal file
@ -0,0 +1,5 @@
|
||||
Chapter 17 - c and cpp extensions
|
||||
=======================================================================================================================
|
||||
|
||||
1. Try to sort a list of numbers using `ctypes`, `CFFI`, and with a native extension. You can use the `qsort` function in `stdlib`.
|
||||
2. Try to make the `custom_sum` function we created safer by adding proper errors for overflow/underflow issues. Additionally, catch the errors when summing multiple numbers that only overflow or underflow in summation.
|
||||
0
CH_17_c_and_cpp_extensions/__init__.py
Normal file
0
CH_17_c_and_cpp_extensions/__init__.py
Normal file
6
CH_18_packaging/README.rst
Normal file
6
CH_18_packaging/README.rst
Normal file
@ -0,0 +1,6 @@
|
||||
Chapter 18 - packaging
|
||||
=======================================================================================================================
|
||||
|
||||
1. Create a `setuptools` command to bump the version in your package
|
||||
2. Extend the version bumping command by interactively asking for a major, minor, or patch upgrade
|
||||
3. Try and convert existing projects from `setup.py` to a `pyproject.toml` structure
|
||||
0
CH_18_packaging/__init__.py
Normal file
0
CH_18_packaging/__init__.py
Normal file
9
README.rst
Normal file
9
README.rst
Normal file
@ -0,0 +1,9 @@
|
||||
Mastering Python Second Edition Exercises
|
||||
=======================================================================================================================
|
||||
|
||||
This repository contains both example exercise solutions and user submitted solutions.
|
||||
|
||||
You are always free to submit your solution, so feel free to jump in and see if you can come up with an improvement
|
||||
or alternative option!
|
||||
|
||||
Naturally code style is a big part of the exercise, so please make sure your code is well formatted and indented.
|
||||
Loading…
x
Reference in New Issue
Block a user