Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Python Data Types Use .split() and .join()

Omar Abu Hamdan
Omar Abu Hamdan
794 Points

banana.py

what is wrong with my code?

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

1 Answer

Tom Slutsky
Tom Slutsky
12,453 Points

well we have couple of issues here. first of all there is no need to call twice to split, neither to join. Both of these methods do not change the input but instead return a new object (list or string).

the real issue though is the join method is used incorrectly. the join method is used on a string object and gets a list as an argument; that means you should use

(', ').join(sundaes)

one more thing is that by calling

menu.format('display_menu')

you are not assigning the formatted string to the variable menu you should probably "prepare" all your variables prior to declaring the menu variable and then call

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

I think this is it