Skip to the content

Project: party guest list

Python · Unit 8: Tuples and sets

Emma and Jake are putting together the guest list for their party, each on their own. Some names are repeated, and some people are on both lists.

With sets you can sort it out in a few lines.

emma = ["Amy", "Leo", "Amy"]
jake = ["Leo", "Mia"]
print(sorted(set(emma)))
both = set(emma) | set(jake)
print(len(both))

Prints

['Amy', 'Leo']
3

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Complete the code

    Complete unique, which returns the list of guests without repeats and in alphabetical order.

  2. 2. Write the code

    Write everyone(a, b), which takes Emma's list and Jake's list and returns all the guests, without repeats and in alphabetical order.

  3. 3. Write the code

    Write in_common(a, b), which returns the people on both lists, without repeats and in alphabetical order. That way they know who they shouldn't invite twice.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →