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()

Watched this video three times now and don't know where I'm going wrong.

So the first 3 lines of codes I can do easily but its the last step + instructions that I do not think I'm doing right. I've seen the video a few times and I feel like I understand what's going on but it's not working. Anyone available to look over my code is greatly appreciated.

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"

sundaes = available.split(";")

menu = "Our available flavors are: {}.".format(display_menu)

display_menu = sundaes.split(", ")

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You can't use a variable before it exists (you're trying to use display_menu before you create it).

Also, sundaes is a list, so it can't be .split(). You need to .join() it, which is a string method, so it starts with a string.

" + ".join([1, 2, 3]) would produce a string like "1 + 2 + 3".

So should I put display_menu before menu to correct that?

This is my current code but it's giving me a "task 1 is no longer passing error"

available = "banana split;hot fudge;cherry;malted;black and white"

sundaes = available.split(";")

display_menu = sundaes.join(", ")

menu = "Our available flavors are; {}.".format(display_menu)

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

That would probably be a good step, yeah :D

After going back to re-watch all your videos I finally figured out what was going on. I had a problem defining and keeping track of strings and lists and what join and split could do. I finally figured it out and completed the task! Thank you Kenneth for your helpful tips!

Current Code:

available = "banana split;hot fudge;cherry;malted;black and white"

sundaes = available.split(";")

display_menu = sundaes.join(", ")

menu = "Our available flavors are: {}.".format(.join(display_menu))

Current Error: "X Bummer! Try again!" I've exhausted all my thoughts. Am I getting closer or missing something here?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

(edited your post for syntax and made it an answer to keep threaded comments cleaner)

Yes, you're closer. But look at my first comment to you. .join belongs to the str class, so it has to have a string in front of it. What you're doing right now is throwing a syntax error (when you have unrunnable code) which is why you're getting just that blank "Bummer".

I apologize Kenneth as I am far too lost at this point. I think I will have to re-watch the whole class from the beginning and take better notes as I cannot for the life of me figure out what's the problem. Thanks for your assistance.