Get startedGet started for free

Counting the elements

In the video, you saw some of Python's most helpful built-in functions.

One of them can be used to count the number of elements in a variable. You'll see three variables in the following steps:

  • course_ratings - a dictionary variable containing course names as keys and average ratings as values.
  • course_completions - a list variable containing the daily number of completions for an individual course.
  • most_popular_course - a string variable containing the name of a course.

You'll practice applying this function to the three variables!

This exercise is part of the course

Intermediate Python for Developers

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

course_ratings = {"LLM Concepts": 4.7, 
                  "Introduction to Data Pipelines": 4.75, 
                  "AI Ethics": 4.62, 
                  "Introduction to dbt": 4.81}

# Print the number of key-value pairs
num_courses = ____(____)
print(____)
Edit and Run Code