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

Patrick O'Brien
Patrick O'Brien
345 Points

what am I supposed to do here?

help, please.

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

sundaes= available.split(";")

menu = "Our available flavors are: {}."

Dispay_Menu= sundaes 

Do you have the Dispay_Menu function? Did you mean to spell it as Display perhaps?

2 Answers

Jeff Wilton
Jeff Wilton
16,646 Points

Yea, it's a little confusing. Basically you need to take the array of values you split the string into, join them back together as strings again (but with a comma and space instead of semi-colon) and use that new string as the placeholder text in the menu string using the format method.

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

sundaes= available.split(";")

display_menu = ", ".join(sundaes)

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

You got the gist of it!

In the 3rd task, it's asking you to use the .join() function. You've already used the .split() function successfully.

Here's how I solved the problem.

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

# display_menu joins the list into separate strings. 
display_menu = ", ".join(sundaes)

# this takes our newly formatted strings and formats it into the string.
menu = "Our available flavors are: {}.".format(display_menu)

Before you solve this task with my example, I highly recommend you to play around in your console so you fully understand .split() and .join(), since you'll be using them a lot in later tasks.

I hope this helps!