
Sean MacDiarmid
3,672 PointsHow 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
colors = ["red,orange,yellow,green,purple"]
1 Answer

Ryan S
27,264 PointsHi 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.
Sean MacDiarmid
3,672 PointsSean MacDiarmid
3,672 PointsHello 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
27,264 PointsRyan S
27,264 PointsHi 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?