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 Use .split() and .join()

Josh Goodhardt
Josh Goodhardt
22,119 Points

Convert string into list

I am having issue with the second stage, making my list become a string. Any ideas?

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
available.split('; ')
sundaes = available

1 Answer

Manish Giri
Manish Giri
16,266 Points

The 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
Josh Goodhardt
22,119 Points

Thanks 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
Manish Giri
16,266 Points

When you use .split() on available, you can just assign the return value to sundaes, like so -

sundaes = available.split(";")