Course program
Introduction, manipulation of strings and files:
- introduction by the teacher, python motivation;
- recap on mutable, immutable objects, passage by reference;
- encoding and decoding; text files, open, with, read, readline, readlines, write, context manager;
- binary files, work with bits and bytes, save an integer on a binary file, convert "by hand" with python binary to decimal, endianness;
- hints to the manipulation of strings;
Functional programming and iterators:
- functions as objects, passing functions to functions, returning functions;
- Iterators and Generators such as eager and lazy evaluation;
- pack and unpack operators; functions with variable arguments args, kwargs;
- functional programming in python (map, filter, any, all, lambda functions);
- short example of using zip () iterator to join two files;
Matrices and Images:
- Definition of Matrix;
- Matrix as a list of lists;
- Create Matrices (various methods; from double cycle to functional with map); Compound Object; Difference between Shallow and Deep Copy;
- Images as matrices; RGB color space; reference system with matrices;
- Draw on images/matrices (draw lines aligned to the axes, rectangles, control to draw inside the matrix);
- Outline of image manipulation (flip concerning vertical and horizontal axis, iterative and functional);
Images, Image, and Object Manipulation:
- Enumerated and zip clarifications
- More on image manipulations, vertical and horizontal flip
- PEP 8 (code style) and PEP 257 (docstring)
- Rotate an image, clockwise and counterclockwise; transpose a matrix; iterative and functional versions
- Blurring filter
- Application case: how to blur only background similar to the "Zoom" filter and similar
- Object-oriented programming
- Objects and classes in python; inheritance
- Example to model a color not as a tuple but as a class
More on object-oriented programming
- Review of what a class is; what is an object, attributes, and methods; classes in Python
- Subclasses, inheritance, operator overloading
- Class attributes and object instance attributes; class methods
- Brief notes on Decorators in Python (@classmethod)
- Exception handling in Python, try-except finally construct.
Homework, Overloading, and Recursion:
- Clarification on operator overloading __eq__
- Package and module in python; how python looks for modules; sys.path
- Image processing «library» with objects as a package to use
- Use of decorators to streamline the code
- Library analysis and digression on design choices
- The concept of recursion; queue and stack data structures; stack of a program
- Recursive Fibonacci and recursion tree
Fibonacci and recursive functions
- Details on how to deal with HW
- Complexity of naive Fibonacci (naive, basic version); exponential growth, an example of wheat grains on a chessboard
- Fibonacci with "memoization"; hints on dynamic programming (DP); Iterative Fibonacci
- Subproblems + base case; divide and conquer
- callable objects in python and the overloading of __call__
- Example of using recursion to print a string without for loop
- Hints to the filesystem as a recursion tree
Various examples of recursion:
- Brief mention on not modifying modules in the HW
- [Recursion] Summarize how to print string character by character without for
- [Recursion] Return and Pass Expressions
- [Recursion] Filesystem as a recursion tree
- [Recursion] Palindrome string (iterative, recursive)
- [Recursion] Binary tree, tree search, pudb debug of the search
Trees and research in depth:
- Study philosophy and exam preparation
- How to create an iterator to the imagemat class to model arrays
- Short recap of Iterator, Iterable, Generator; functions with variable arguments (args, kwargs)
- [Recursion] Enumerate (and get) the permutations of a set as a recursive problem
- [Recursion] DFS depth-first-search (pre / in / post order) on binary tree
- [Recursion] Arithmetic expressions as binary tree (browse them in pre / in / post)
Homework:
- Strategic advice on how to deal with HW and manage time
- Analysis of the HW6 problem and possible ways to solve it, various ideas and solution schemes
- Analysis of the data provided
- Review of images / matrices as a list of lists (difference between row and column access)
- Importance of how you write the code and its style
- Notes on DAG (Direct Acyclic Graph)
Artimetic Expressions such as Binary Tree
- Review on callable objects
- Review of images / matrices as a list of lists (difference between row and column access)
- Importance of how you write the code and its style
- Notes on DAG (Direct Acyclic Graph)
Arithmetic Expressions such as Binary Tree
- Review on callable objects
- Review on * args, ** kwargs
- Our defaultdict (use with care and caution)
- Additional clarifications on TraceRecurision (based on __call__)
- Arithmetic expressions as a binary tree
- Concept of parser and grammar
- Create a parser for arithmetic expressions with binary tree
- Parenthesis management
- Management of expression and split in tokens
- Complete parser of Arithmetic Expression
- Resolution and Print of in-order expressions
Game Trees:
- From Binary tree to N-ary tree
- Branching factor of a tree
- Review of the Filesystem as an N-ary tree with variable branching factor
- Recap Recursion for calculating permutations, but with branching factor and complexity analysis
- Game Tree: Node: State = Arc: Move; Game tree as an N-ary tree.
- Example of “enumeration” of the possible moves in the thread game with recursion
- Indexing of the board only with [] and slice e.g. A [:, c] selects column c-th.
- Drafting of the modular code for enumerating thread moves
Homework and Course Conclusion:
- From recursive version to how to write an iterative version
- Review on Game Trees
- Hints to the python argparse module to handle complex input inputs
- Brief introduction to Jupyter Notebook
Prerequisites
No requirements.
Books
Allen B. Downey - Thinking in Python (2nd edition)
Frequency
Recommended.
Exam mode
Computer-based exam: development of python code.
Bibliography
Charles Dierbach - Introduction to Computer Science Using Python: A Computational Problem-Solving Focus
Python 3 Tutorial - https://docs.python.org/3/tutorial/
Other useful tools:
PEP 8 - Style Guide for Python Code - How to write elegant code in python - https://www.python.org/dev/peps/pep-0008/
PEP 257 - Docstring Conventions - Documentation of functions with docstring - https://www.python.org/dev/peps/pep-0257/
Lesson mode
Lectures and computer lab sessions.