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

Luke Wunderlich
Luke Wunderlich
759 Points

What should I do?

I'm learning splitting and joining lists in Python. The first task asks me to split the available variable by the semicolons:

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

That part worked fine. Second task was putting in the menu variable:

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

I just can't figure out the third task which is asking me to join the available list with a comma and a space, then formatting it to the menu variable.

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

Once I run the code, it tells me that task 1 is no longer passing. Any help?

1 Answer

Rick Buffington
PLUS
Rick Buffington
Courses Plus Student 8,037 Points

The problem you are facing starts with your join command. You need to call the join command on a string, not the array.

", ".join(sundaes)

So in essence, they want you to substitute that in the output somehow (I don't know the exact challenge so I can't tell you for sure, but this should get you in the right direction).

print menu.format(", ".join(sundaes))

Hopefully that helps.

Luke Wunderlich
Luke Wunderlich
759 Points

After I add your first line of code, it gives me the same warning. "Task 1 is no longer passing." And if I add both of them, it gives the same warning, and if I add only the second line, it gives the same warning also.

Rick Buffington
Rick Buffington
Courses Plus Student 8,037 Points

1) Create a variable named sundaes that uses split

sundaes = available.split(";")

2) Assign a new menu variable to the string "Our available flavors are: {}."

menu = "Our available flavors are {}."

3) Using .format() on the menu variable, join the sundaes items with ", " and assign them to a new menu variable.

menu = menu.format(", ".join(sundaes))

That should complete all of the tasks. They want you to overwrite by assignment the menu variable using the format function and the join functions.