Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Set basics
9. Iterating over sets
Relationships between sets
Summary

Instruction

Excellent job! Unlike lists or tuples, sets are unordered. This means that you can't use square brackets to access set elements. Instead, you can iterate over the set, like this:

favorite_movies = {'Halloween', 'A Star Is Born', 'Hocus Pocus'}
for movie in favorite_movies:
  print('There are', len(movie), 'letters in the title', movie)

Note that the order of set elements is non-deterministic. This means that you can get a different ordering each time you create a for loop.

Exercise

The new branch hired some new people. Write a welcome message to each of them, using a new line for every person:

Welcome on board, {name}!

Stuck? Here's a hint!

Use a for loop:

for employee in new_branch_employees: