Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Solving Problems with Built-in Python Types

To be effective with Python we need to be comfortable using the basic data types that Python has to offer. In this Hands-On Lab, we'll be utilizing basic types to fix some failing automated tests, and ensuring that the application is working correctly. By the time we're finished with this hands-on lab we should be more comfortable using the different data types in Python, like strings, numbers, dictionaries, and lists.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Sep 18, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Implement `print_todo` function

    The print_todo function needs to print out a string that uses the name and body values from a dictionary. To do this, we can utilize the print function and an f-string (using Python 3.6 and higher). Here's one way we could implement this function:

    def print_todo(todo):
        """
        print_todo takes in a todo dictionary and prints it out
        with by separating the `name` from the `body` using a colon (:).
    
        >>> todo = {'name': 'Example 1', 'body': 'This is a test task', 'points': '3'}
        >>> print_todo(todo)
        Example 1: This is a test task
        >>>
        """
        print(f"{todo['name']}: {todo['body']}")
    

    If we run the tests, we should see there are now no failures related to print_todo.

  2. Challenge

    Implement `take_first` function

    The take_first function needs to return two objects to us, in the form of the first todo and the remaining todos. We can achieve this by returning a tuple of values, and the pop function on a list should allow us to get the first item. Here's one way we might implement this function to get the tests passing:

    def take_first(todos):
        """
        take_first receives a list of todos and removes the first todo
        and returns that todo and the remaining todos in a tuple
    
        >>> todos = [{'name': 'Example 1', 'body': 'This is a test task', 'points': '3'},
        ... {'name': 'Task 2', 'body': 'Yet another example task', 'points': '2'}]
        >>> todo, todos = take_first(todos)
        >>> todo
        {'name': 'Example 1', 'body': 'This is a test task', 'points': '3'}
        >>> todos
        [{'name': 'Task 2', 'body': 'Yet another example task', 'points': '2'}]
        """
        todo = todos.pop(0)
        return (todo, todos)
    
  3. Challenge

    Implement `sum_points` function

    The sum_points function needs to receive two todo dictionaries and return the sum of the point values. The doctest shows the point values will be strings, so we'll need to convert them to be integers before we perform our addition. Here's one way we could get these tests passing:

    def sum_points(todo1, todo2):
        """
        sum_points receives two todo dictionaries and returns the sum of their `point` values.
    
        >>> todos = [{'name': 'Example 1', 'body': 'This is a test task', 'points': '3'},
        ... {'name': 'Task 2', 'body': 'Yet another example task', 'points': '2'}]
        >>> sum_points(todos[0], todos[1])
        5
        """
        return int(todo1['points']) + int(todo2['points'])
    
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight