Note: in some of these exercises, the solutions are shown as functions. If you see the def
keyword in the solution, that's what's going on. We haven't learned functions yet, although you might be able to recognize some of the main ideas from C++. In any case, you can usually understand the solution just by focusing on what comes after the line involving def
.
- Radius of a circle: Exercise 4
- Nearby numbers: Exercise 17
- Character swaps: Exercise 5
- Pythoning: Exercise 6
- "Writing" HTML: Exercise 15
Note: in some of these exercises, the solutions are shown as functions. If you see the def
keyword in the solution, that's what's going on. We haven't learned functions yet, although you might be able to recognize some of the main ideas from C++. In any case, you can usually understand the solution just by focusing on what comes after the line involving def
.
- Largest number from a list: Exercise 3.
- Removing duplicates in a list: Exercise 7.
- Splitting lists: Exercise 51.
- Draw a triangle: Exercise 4.
- Counting evens and odds: Exercise 6.
- Password validation: Exercise 15.
Note: in some of these exercises, the solutions are shown as functions. If you see the def
keyword in the solution, that's what's going on. We haven't learned functions yet, although you might be able to recognize some of the main ideas from C++. In any case, you can usually understand the solution just by focusing on what comes after the line involving def
.
- Updating a dictionary: Exercise 2. Note: there is at least one other good solution.
- Iterating over key-value pairs: Exercise 9.
- Top items in a dictionary: Exercise 30.
- Manipulating tuples: Exercise 21.
- Checking for subsets: Exercise 10. For this one, you may want to Google around rather than trying to "manually" solve this one.
- Checking a range: Exercise 6.
- Checking a palindrome: Exercise 12.
- String Rearrangement: Exercise 15.
- Sorting with lambda functions: Exercise 3.
- String in, STRING out: Exercise 9.
- A circle class: Exercise 11.
Note: most of the exercises on this page are helpful and nicely illustrated visually. I've selected just a few.
- Generating and subsetting arrays: Exercise 19.
- Generating and subsetting arrays: Exercise 22.
- Picture frame: Exercise 28.
- Fahrenheit to Celsius: Exercise 14.
- Finding large elements: Exercise 31.
Note: You can learn something useful from most of the exercises on the linked page. However, if you're not sure how to do something, it's worth trying to Google around for an appropriate numpy
function rather than trying to build your approach "from scratch."
- Mean across axes: Exercise 19
- More axis tricks: Exercise 27
- Filtering practice. All the exercises on this page are quite useful, actually. A few you could try first are Exercises 1, 2, 4, and 12. The best way to start these exercises is by downloading the supplied data and reading it with
pd.read_csv()
. - Detecting NaN values: Exercise 2.
- Counting NaN values: Exercise 3.
- Dropping rows: Exercise 5.
- Dropping rows again: Exercise 7.
- Split-apply-combine practice: Exercise 2. The easiest way to get the data for this example is to copy and paste the text into a CSV file and read it in via
pd.read_csv()
- Counting unique values: Exercise 15. You might want to Google around for a relevant function here.