Count with dictionaries
Split a sentence with split() and update a dictionary safely with get(word, 0).
Work through 4 Python practice exercises on dictionaries, list comprehensions, functions and strings. Run each starter in your browser, use hints when needed and compare your result with the complete solution.
You should recognise strings, lists and a basic for loop. The lessons explain dict.get, the remainder operator, sum and len, and the [::-1] slice as they appear.
Split a sentence with split() and update a dictionary safely with get(word, 0).
Use a list comprehension to keep only even numbers and square them.
Return the average of a list and decide what an empty list should return.
Lowercase a word and compare it with its reversed slice to find palindromes.
Split the sentence on whitespace and count each word with a dictionary. Print the counts for code and learn.
Use a list comprehension to build a list containing the square of every even number. Print the list.
Define average(numbers) so that it returns the mean of a list of numbers, and returns 0 for an empty list. Print the average of scores and of an empty list.
For each word, print True if it reads the same backwards when you ignore upper and lower case, and False otherwise.
Predict the output before running each program. Use the hint to get unstuck, then compare your program with the complete solution. Change the input to explore case differences, empty lists and punctuation.
Python uses a browser WebAssembly runtime. It does not provide arbitrary operating-system access, unrestricted networking or every pip package.
Completion is self-reported. There is no automated grading, and progress is saved only on this device.