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

Reassign the Menu Variable?

I'm currently stuck on this step. I'm not sure how to reassign menu variable. Please help! Thanks so much.

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

1 Answer

Kieran Barker
Kieran Barker
15,028 Points

The longer (and arguably easier to read) way is to do it like this:

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)

Or, if you want to do it in one line, you can do this, forgoing the need for a display_menu variable at all:

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

Kieran, thank you so much for your thorough answers! I'm an art major trying to myself how to code, so this very foreign to me, haha. I really appreciate your help!

Kieran Barker
Kieran Barker
15,028 Points

You’re welcome! It can be confusing as hell sometimes. Keep it up ?