How to loop over python dictionaries and Numpy arrays

Premium

In the previous lessons, we learned about how to loop over lists. In this lesson, we will learn about how to loop over python dictionaries and Numpy arrays.

Loop over dictionaries

To loop over a dictionary elements, we use the items() method provided with a dictionary object. Let's say we have the following dictionary containing the a list of stocks along with their prices.

1portfolio = {"GOOGL":849, "FB":136, "MSFT":64, "AAPL":136, "AMZN":848}
2
Continue Reading
Premium Content

This tutorial is a part of the course Python for Data Science. This is a premium course. The purchase options for the course are provided below. With this course, you get access to complete course content, source code, practical exercises, and all resources that are a part of the course.

Lifetime Premium Membership
$250
$179

Get unlimited access to all courses and premium content

Join Premium
Individual Course
$7

Purchase this course individually

Purchase CourseView Course Details
What's Included:
Complete access to course content and updates
All downloadable resources
Interactive course quizzes
Practice exercises and sample code
Ad-free learning experience