Foundations of Python Programming¶
Runestone Academy FOPP is a practical free online book with many projects and related ‘hands on’ theory, definitely recommended!
Note on graphics: to make activities more interesting, the book often asks to visualize data with the following libraries:
turtleis a Python module which was designed really only for didactical purposes. While fun, you will most probably want to try doing the same exercises using a more ‘serious’ library like
cimage: this is a simple image manipulation library, made mostly for didactical purposes: you might want to try numpy and matplotlib instead
altairis a ‘pro’ library for cool interactive visualizations: we don’t treat
altairin this book, you can try it or stick with the good old
Contains many simple exercises on Python basics, do them!
Software Carpentry is a website full of free educational resources, there is definitely a lot of good stuff to discover. We highlight these exercises (in tutorial format):
Programming with Python: Nice tutorial with many exercises about processing a csv with topics: python basics, numpy, csv
Plotting and programming with Python More advanced, uses pandas
Contains many python exercises with solutions. Here we put a small selection, for others you may look at ‘Very hard’ level, they are not so hard after all.
Edabit - Strings¶
Edabit - Lists¶
Website with collections of exercises sorted by difficulty and acceptance rate, quite performance-oriented. You can generally try sorting by Acceptance and Easy filters.
We put here a selection.
LeetCode - Strings¶
Check string problems sorted by Acceptance and Easy. In particular:
LeetCode - Lists¶
Check array problems sorted by Acceptance and Easy. In particular:
Missing number - has many possible solutions
Largest Perimeter Triangle hint: you don’t actually need to try many combinations …
The k Strongest Values in an Array a bit convoluted but doable
Array partition 1 actually a bit hard but makes you think
Reorganize String think first when the task is not possible, for the rest is like previous one
LeetCode - Sets and Dictionaries¶
Check dictionary problems sorted by Acceptance and Easy.
Note: Keep in mind these problems are in section dictionaries for good reason: in order to execute fast they often require you to preprocess the data by indexing in it in some way, like i.e. putting strings in a set or as keys in a dicitonary so you can later look them up very fast.
WARNING: if you feel the need to use nested cycles, or search methods on lists/strings like
.replace on strings, try thinking first whether it is really necessary or you might use the above mentioned preprocessing instead.
Check in particular:
LeetCode - Matrices¶
Kth Smallest Element in a Sorted Matrix - there are many possible optimizations, you can make a first version using
sorton everything, and then think about improving the algorithm
Set Matrix Zeroes interesting, try avoiding duplicating the matrix
Sort the Matrix Diagonally not fun, but doable
Contains many Python 3 exercises on algorithms and data structures (Needs to login)
Geeks for Geeks¶
Contains many exercises - doesn’t have solutions nor explicit asserts but if you login and submit solutions, the system will run some tests serverside and give you a response.
In general for Part A you can filter difficulty by school+basic+easy and if you need to do part B also include medium.
You can select many more topics if you click
more>> un der Topic Tags:
Dive into Python 3¶
More practical, contains more focused tutorials (i.e. manage XML files)
Introduction to Scientific Programming with Python¶
Focuses on numerical calculations, you can check first 7 chapters until dictionaries.
By Joakim Sundnes.
PDF for Python (only theory)
Exercises – a LOT of stuff, although some exercises are too much into engineering / maths compared to this book
EXTRA: if you like, it also contains chapters on classes which are certainly useful.