Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

David P
PLUS
David P
Courses Plus Student 1,162 Points

I have tried every which way to get the syntax correct. I know this may be an easy one, but I cannot get it to work.

I think it's a good idea for you to experiment with sets since they're a very useful part of Python. Start by creating a set variable named songs that has three song titles in it. You can use any titles you want, just make sure they're three different strings.

sets.py
def songs = ('titles')
def titles = ['Song1', 'Song2', 'Song3']
    set(['titles'])

1 Answer

Stuart Wright
Stuart Wright
41,102 Points

The correct syntax is:

songs = {'song1', 'song2', 'song3'}

The 'def' keyword is only used for function definitions, not variable assignments. And it's curly braces you need to create a set.

Alexander Peterson
Alexander Peterson
Courses Plus Student 3,832 Points

I just want to add, if you wanted to have a list of titles and make it into a set later:

titles = ['Song1','Song2','Song3']
set_of_titles = set(titles)