FAQ: Sets - Set Union

This community-built FAQ covers the “Set Union” exercise from the lesson “Sets”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Set Union

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I have a question about this exercise. I percieve that the goal is to to use union to merge the tag sets togather so that we have a full collection of tags. I see that the code loops over song_data(items()) and grabs the keys and values of the song_data dictionary.

song_tag_set = set(val) → so this would be going over the song_data dictionary and grabbing the values at each iteration. I observe if I print it that it targets ‘Lowkey Space’ keys.

user_tag_set = set(user_tag_data[key] → When I print this I observe it targets user_tag_data dictionary and prints the ‘Lowkey Space keys’.

Why aren’t the for loops inputting into the sets all of the keys such as ‘Retro Words’ ‘Wait For Limit’ ‘Stomping Cue’ and ‘Lowkey Space’?

Why isn’t user_tag_set not holding all of the key values of user_tag_data. such as ‘Lowkey Space’, ‘Retro Words’, ‘Wait For Limit’ ‘Stomping Cue’

What exactly is going on in this code?

Link to Exercise: Learn Intermediate Python 3 | Codecademy

song_data = {'Retro Words': ['pop', 'warm', 'happy', 'electronic'],
             'Wait For Limit': ['rap', 'upbeat', 'romance'],
             'Stomping Cue': ['country', 'fiddle', 'party'],
             'Lowkey Space': ['electronic', 'dance', 'synth']}

user_tag_data = {'Lowkey Space': ['party', 'synth', 'fast', 'upbeat'],
                 'Retro Words': ['happy', 'electronic', 'fun', 'exciting'],
                 'Wait For Limit': ['romance', 'chill', 'rap', 'rhythmic'], 
                 'Stomping Cue': ['country', 'swing', 'party', 'instrumental']}

# Write your code below!
new_song_data = {}

for key, val in song_data.items():
  song_tag_set = set(val) # targets 'Lowkey Space'
  user_tag_set = set(user_tag_data[key]) # targets Lowkey Space
  new_song_data[key] = song_tag_set.union(user_tag_set)

print(song_tag_set)
print(user_tag_set)
1 Like