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

SISLEY NGUYEN
SISLEY NGUYEN
1,835 Points

Alright, let's finish making our menu. Combine the sundaes list into a new variable named display_menu, where each item

Alright, let's finish making our menu. Combine the sundaes list into a new variable named display_menu, where each item in the list is rejoined together by a comma and a space (", "). Then use .format() on our existing menu variable to replace the placeholder with the new string in display_menu. If you're really brave, you can even accomplish this all on the same line where menu is currently being set

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes=available.split(';')
menu=("Our available flavors are: {}." )
display_menu.join("sundaes", "menu")
display_menu = "Our available flavors are: {}.".format(", ".join(sundaes))

8 Answers

David Hamilton
David Hamilton
21,522 Points

You are close, to do it one line it just needs to be on the menu variable. Below is how I did it.

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu = ("Our available flavors are: {}." ).format(", ".join(sundaes))
Bo Winters
seal-mask
.a{fill-rule:evenodd;}techdegree
Bo Winters
Full Stack JavaScript Techdegree Student 1,481 Points

David,

I did everything Garrett said multiple times on my own and it never worked. I did your method and it worked. I'm just confused because in your method you never assign the variable "display_menu" - am I missing something?

David Hamilton
David Hamilton
21,522 Points

Hello Bo,

My code is showing the solution to do the last task on one line. When doing it this way you do not need to create the "display_menu" variable.

The code in Garrett's answer should work. Below is the code I used when doing the solution with the "display_menu" variable.

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)

Hi Sisley,

The first thing we do is:

  • split the available string on ";" and assign it to the variable sundaes
  • then we will join that new string in the variable sundaes on ", "
  • assign that new string to the variable display_menu
  • then we will use the .format(display_menu) to show the correct string in the placeholder in the menu variable

Hope this helps and best of luck!

Garrett

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)
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu ="Our available flavors are: {}.".format(", ".join(sundaes))
display_menu = menu

my answer

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

sundaes= available.split(";")
menu= "Our available flavors are {} "
display_menu= ", ".join(sundaes)
menu= menu.format(display_menu)

LOL! It will not let me do it all on one line due to Challenge 1 & 2. Guess I get an A++ for this one.

menu = "Our available flavors are: {}.".format(", ".join("banana split;hot fudge;cherry;malted;black and white").split(";"))

I found I needed to delete this line: display_menu = ", ".join(sundaes)

Then put this part: ", ".join(sundaes) inside format.

It finally passed!! : )

With this variable and value ---> display_menu = ", ".join(sundaes) <---- still there I kept getting errors.

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

available = "banana split;hot fudge;cherry;malted;black and white" sundaes = available.split(';') menu = ("Our available flavors are: {}." ).format(", ".join(sundaes))

Gabriel Reed
Gabriel Reed
560 Points

It's absolutely impossible to figure this out just based solely on the video. Can you guys seriously not stick to the content you thus far created??

Agreed especially us that is very new to Python. :)

I agree, I am becoming more and more frustrated with this course. The video content does not provide enough information to complete these quizzes.