Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Sets First Sets

please help

sets.py

sets.py
songs = {'song1','song2','song3'}
songs.add('Treehouse Hula')
songs.update({'Python Two-step'},{'Ruby Rhumba'},{'My PDF Files'})

2 Answers

nick schubert
nick schubert
3,535 Points

I don't know what your exact question is, but I assume that you're trying to add song4.

I would personally do it like this:

songs = {'song1': 'Python Two-step', 'song2': 'Ruby Rhumba', 'song3': 'My PDF Files'} 
# Now, I assume you wish to add song4 which you can do in multiple ways.
songs['song4'] = 'Treehouse Hula'
# You can also add a song like this:
song4 = { 'song4' = 'Treehouse Hula' }
songs.update(song4) # I personally find it easier to do the first method. 
Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

Blessing you are essentially correct. The automated grader was looking for EXACT case

You mistakenly did not put a capital S on "Python Two-step" where it should have been "Python Two-Step"

Under Python3 (workspaces) your code produces this set ordering-- in theory, a set has no order.

songs = {'song1','song2','song3'}
songs.add('Treehouse Hula')
songs.update({'Python Two-step'},{'Ruby Rhumba'},{'My PDF Files'})
print(songs)

$ python blessing.py
{'song2', 'Treehouse Hula', 'song3', 'song1', 'Ruby Rhumba', 'Python Two-step', 'My PDF Files'}

I wrote the code how I think the teacher wanted it (I cut-and-pasted), and it passed the challenge. But, it produces an equivalent set with a different "ordering".

songs = {'song1', 'song2', 'song3'} # instantiation of songs set object
songs.add('Treehouse Hula') # a simple addition of a string object
songs.update({"Python Two-Step", "Ruby Rhumba"}) # update songs with another 2 item set
songs.update({"My PDF Files"}) # update songs with a 1 item set

Under Python3 (workspaces) produces this ordering, but it is equivalent to Blessing's set.

$ python jeff.py
{'song1', 'Python Two-Step', 'My PDF Files', 'Ruby Rhumba', 'Treehouse Hula', 'song3', 'song2'}

Don't worry about it, enjoy Python! *Sometimes the computer tests aren't smart enough to recognize a student got the right answer or something really close to it! *