Teacher's Guide
Chapter 3 / Level 5: Sorting Sets
Teaching Objective:
- Student learns more applications and use cases for the Set functions
- Understands how to use the
symmetric_difference()anddifference()Set functions - Learns how to interface various Set functions together to achieve results
Guide
In this exercise we will be working with more advanced Sets as well as practicing Sets learned in the previous level. Set’s can be used to sort out, separate and consolidate items inside a list. The objective in this level is to collect, sort and combine several lists into Sets in order to cook meals.
Start off by walking to the dark X mark over the orange carpet and collecting the list constants named pack1 and pack2 . Face the refrigerator and use the collect() function to grab the lists.
player.collect(pack1)
player.collect(pack2)
Walk to the light X mark and face the cutting board and sort out the items in the lists by converting them into Sets. First verify the contents of the lists using the speak() function, then transfer the contents into Sets named set1 and set2 .
player.speak(pack1)
player.speak(pack2)
.............
set1 = set(pack1)
set2 = set(pack2)
Continue on into sorting out the items by comparing and separating them into smaller Sets. First create a set named unique and use the symmetric_difference method in order to separate the items from the set that are not shared between each other. Follow this up by creating a Set named shared and use the intersection method that holds the items that are shared between the two lists.
Create two more Sets named meat1 and meat2 , use the difference method in order to separate the items are only found in the specific Sets when compared. In all these instances, use the speak() function in order to verify the contents of the Sets.
unique = set1.symmetric_difference(set2)
player.speak(unique)
shared = shared = set1.intersection(set2)
player.speak(shared)
meat1 = meat1 = set1.difference(set2)
player.speak(meat1)
meat2 = meat2 = set2.difference(set1)
player.speak(meat2)
Once everything has been sorted, walk to the dark X mark over the blue carpet an place() the shared Set into the refrigerator.
player.place(shared)
Walk to the gold X mark and face the cabinet, use the collect function to grab the third list constant named ingredients . Transfer this list into a Set named set3 using the set() function. Follow this up by combining set3 with the meat1 and meat2 Sets. Use the the union method to merge the Sets together in order to prepare meals for cooking.
player.collect(ingredients)
set3 = set(ingredients)
meal1 = set3.union(meat1)
meal2 = set3.union(meat2)
Finally, walk to the dark X mark over the purple carpet and use the speak() function to verify the meal1 Set before using the place() function to pour it in the pot. Do the same thing with the meal2 set on the yellow carpet X mark in order to complete the level.
player.speak(meal1)
player.place(meal1)
...............
player.speak(meal2)
player.place(meal2)
Map overview and path

Code Solution
import player
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward()
player.collect(pack1)
player.collect(pack2)
player.turn_right()
player.move_forward(6)
player.speak(pack1)
player.speak(pack2)
set1 = set(pack1)
set2 = set(pack2)
unique = set1.symmetric_difference(set2)
player.speak(unique)
shared = shared = set1.intersection(set2)
player.speak(shared)
meat1 = meat1 = set1.difference(set2)
player.speak(meat1)
meat2 = meat2 = set2.difference(set1)
player.speak(meat2)
player.turn_left()
player.turn_left()
player.move_forward(3)
player.turn_right()
player.place(shared)
player.turn_left()
player.move_forward(5)
player.turn_right()
player.collect(ingredients)
set3 = set(ingredients)
meal1 = set3.union(meat1)
meal2 = set3.union(meat2)
player.turn_right()
player.move_forward(3)
player.turn_left()
player.speak(meal1)
player.place(meal1)
player.turn_right()
player.move_forward()
player.turn_left()
player.speak(meal2)
player.place(meal2)
v

Code Solution
import player
player.turn_left()
player.move_forward(4)
player.turn_right()
player.move_forward()
player.speak(left_sack)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.speak(middle_sack)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.speak(right_sack)
potatoes = [x for x in left_sack if not "Spoiled" in x]
onions = [x for x in middle_sack if not "Bad" in x]
garlic = [x for x in right_sack if not "Rotten" in x]
player.turn_left()
player.turn_left()
player.move_forward(2)
player.turn_left()
player.move_forward()
player.turn_right()
player.place(garlic)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.place(potatoes)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.place(onions)