THE PRACTICE LIBRARY

Python practice: time formatting, strings, and collections

Practice Python in your browser with real tests. Format recording durations, work with strings and collections, and build up to more advanced exercises.

Try a beginner challengeLearn the concepts first

No account needed. Progress and drafts are saved on this device.

Start with time: format a recording duration

A recording length is a duration, not a time of day. Separate a total number of seconds into hours, minutes, and seconds. Keep hours above 23 instead of wrapping to a new day. Formatting and arithmetic are separate parts of this problem: minutes and seconds always need two digits.

The problem

Turn a nonnegative whole number of seconds into a string in H:MM:SS format. Hours have no leading zero and may exceed 23. Minutes and seconds must each use two digits. For example, 61 becomes "0:01:01". The argument is always an integer, not a boolean.

Example input90061 secondsExpected result"25:01:01"

Write your answer in the editor, then choose Run tests. Each check shows what was expected and what your code returned. Reveal hints one at a time; the solution stays behind the solution button.

Open format a recording duration

Python challenges

12 of 12
PythonIntermediate

Map an import row to field names

Given a list of unique column-name strings and a list of values, return a dictionary that pairs each column with the value at the same position.

Dictionaries · enumerate · Positional data

Open challenge
PythonIntermediate

Read a quoted CSV export

Parse CSV text into a list of dictionaries, using the first row as field names and keeping data rows in their original order.

csv.DictReader · Standard library · Text parsing

Open challenge
PythonIntermediate

Fill missing days in an activity report

Given events of the form {"date": "YYYY-MM-DD", "count": integer}, return one {"date", "count"} dictionary for every date from start_date through end_date, inclusive and ascending.

datetime.date · timedelta · Dictionaries · Date ranges

Open challenge
PythonIntermediate

Compress consecutive status events

Given a list of status strings, replace each consecutive run of equal statuses with {"status": string, "count": integer}.

itertools.groupby · Iteration · Run-length encoding

Open challenge