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 Basics (2015) Python Data Types List Creation

How to make lists

Having trouble making list:

I'm using syntax to make list as:

colors = [red, orange , yellow, green , purple]

I've used with and without "" marks, still getting syntax error, I've watched video twice and not sure what I am missing to make list

lists.py
colors = ["red,orange,yellow,green,purple"]


1 Answer

Ryan S
Ryan S
27,276 Points

Hi Sean,

If you want to create a list of strings, you'd need to make sure that each individual item is in quotes. Once you establish that, then each item will be separated by a comma outside of the quotes.

colors = ["red", "orange", "yellow", "green", "purple"]

Your first example (the one without quotes) would work if each item in the list was a variable. But you'd need to assign a value to them first.

red = "red"
orange = "orange"
yellow = "yellow"
green = "green"
purple = "purple"
colors = [red, orange, yellow, green, purple]

Your other example (the entire list of colors inside quotes) is really only creating a list with one item.

colors = ["red,orange,yellow,green,purple"]

# The one item in the list is "red,orange,yellow,green,purple"

Whatever is inside a pair of quotes is considered one item, a single string. So the commas are also included in that string.

Hope this helps.

Hello Ryan,

Thank you very much for that advice. I did try and create the string exactly how you describe is the correct way and am still getting a syntax error message when I do the code challenge. Could this be a "bug" in the course I am taking? Again, I did it exactly the way you described.

Thanks! :)

Ryan S
Ryan S
27,276 Points

Hi Sean,

That is very strange. If I copy and paste this exact line into the challenge it passes for me.

colors = ["red", "orange", "yellow", "green", "purple"]

If that isn't working for you then I'm not sure what is going on. Would you be able to post the code that you are trying?