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

I'm a bit stuck on .split and .join what I've written looks correct but it cancels faze 1

my question says part 1 is wrong but I do not see the problem with the code. but there probably is mind helping?

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.join(", ")

1 Answer

You have used .split() correctly. However, I see a problem with your code elsewhere. Remember, python reads your code from top to bottom, and left to right. Order is very important (as well as indentation and similar formatting conventions)! If you look at your code carefully, you will see you've referenced a variable before it has been defined. Simply move your variable definition and task 1 will pass.

The reason this causes part 1 to fail, is because this throws an exception while the code is parsing, before the part 1 tests can be completed. It is useful to bear in mind that "part 1 no longer passing" does not always mean there is a problem directly in the code you submitted for the first part of the challenge.

There is another problem with your use of .join(). You are close, but .join gets called on a string, and is passed a list; you've done this backwards. It should look like:

', '.join(sundaes)