References
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:
turtle
is 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 likematplotlib
cimage
: this is a simple image manipulation library, made mostly for didactical purposes: you might want to try numpy and matplotlib insteadaltair
is a ‘pro’ library for cool interactive visualizations: we don’t treataltair
in this book, you can try it or stick with the good oldmatplotlib
W3Resources website
Contains many simple exercises on Python basics, do them!
Software Carpentry
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
You may find other stuff in Community Developed Lessons for Jupyter and Python
Edabit
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 - Basics
Edabit - Strings
Edabit - Lists
Edabit - Dictionaries
Edabit - Matrices
Layers in a Rug, a bit convoluted, but interesting
LeetCode
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
Filter Restaurants by Vegan-Friendly, Price and Distance (to sort use lambda functions)
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 .index
, .find
, in
operator, .count
, .replace
on strings, try thinking first whether it is really necessary or you might use the above mentioned preprocessing instead.
Check in particular:
Verifying an alien dictionary Note: you can use lambda functions, but it is not strictly necessary
People Whose List of Favorite Companies Is Not a Subset of Another List
LeetCode - Matrices
Kth Smallest Element in a Sorted Matrix - there are many possible optimizations, you can make a first version using
sort
on everything, and then think about improving the algorithmSet Matrix Zeroes interesting, try avoiding duplicating the matrix
Sort the Matrix Diagonally not fun, but doable
Leet code - Graphs
Note: here on softpython we do not put links to exercises about visiting graphs, so for these you do not need stuff like breadth first search, depth first search, etc.
HackerRank
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)
Licence: Creative Commons By Share-alike 3.0 as reported at the bottom of book website
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.
[ ]: