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

Jason Cohen
Jason Cohen
232 Points

.variable with display_menu

Ive made the display menu joined via 'sundaes' and the menu.

Not sure what im missing here.

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

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

I took a break, and looked at it with fresh eyes

I realise that sundaes is not essential anymore, as it is basically 'available' that is split.

So i made display_menu equal available and then joined.

I then formatted 'display_menu'

Please see below...

Am in on the right lines here in my thinking?

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

display_menu = available.joined(", ").format(display_menu)

Manish Giri
Manish Giri
16,266 Points

I think these lines are wrong -

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

First, your method is wrong, it should be .join(), not .joined(). Next, you want to plug in the value of the string display_menu in menu, so you shouldn't have sundaes in .format(). It should be " .... {}".format(display_menu).

This was my solution-

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

1 Answer

Afloarei Andrei
Afloarei Andrei
5,163 Points

In display_menu you have to join sundaes > ", ".join(sundaes) In menu you have to format the placeholder to hold the joined sundaes with a ",". (remove 'display_menu' from {} and add it in format. > menu = "string {}".format(display_menu)

Jason Cohen
Jason Cohen
232 Points

Thanks Andrei, thinking through your reply.

I also just posted an update before I saw your message.

Am I on the right lines there?

Thanks

Afloarei Andrei
Afloarei Andrei
5,163 Points

You will get a "AttributeError: 'str' object has no attribute 'joined'"

Try to do it local in python so you see when you do something wrong and do the entire challenge step by step.

When you use the split() syntax the "available" string transformed into a list like this: ['banana split', 'hot fundge', .........]

To join all the flavors in the list you have to use the join() syntax like this: ", ".join(sundaes) #sundaes is the list with flavors

And finaly to print the menu you use the format() syntax. "string {}".format() #what you want to print in the curly brackets {} you add it in this brackets ()

you can do it on the same line by adding the join() in the format brackets () like this: "string {}".format(", ".join(sundaes))