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 trialJosh Goodhardt
22,119 PointsConvert string into list
I am having issue with the second stage, making my list become a string. Any ideas?
available = "banana split;hot fudge;cherry;malted;black and white"
available.split('; ')
sundaes = available
1 Answer
Manish Giri
16,266 PointsThe first problem lies here -
available.split('; ')
sundaes = available
You're splitting your string into a list on this line - available.split('; ')
, but this does not change the string available
itself. This returns a new list instead. Since you're not saving the return value anywhere, you're essentially losing the returned list. On the next line when you write - sundaes = available
, this just sets sundaes
to the original string itself.
The second problem is here -available.split('; ')
. You should split on just ;
. You have a space after ;
currently.
Josh Goodhardt
22,119 PointsJosh Goodhardt
22,119 PointsThanks for that advice. How do I convert that return value from a list to a string? What do I need to do in between to make it work?
Manish Giri
16,266 PointsManish Giri
16,266 PointsWhen you use
.split()
onavailable
, you can just assign the return value tosundaes
, like so -sundaes = available.split(";")