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

Chase Frankenfeld
Chase Frankenfeld
6,137 Points

I have double and triple checked in the Python Shell, and my code works. I am not sure of how to format for the quiz?

This is specifically for the final question.

For questions one and two, which were correct:

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

For the 3rd question, not sure if it should be written like this:

menu = "Our available flavors are {}."

# OR?


", ".join(sundaes)  --> then underneath
menu.format(", ".join(sundaes))  

# OR whether I should name them?

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

# OR whether it should be written like this?

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

[MOD: added ```python markdown formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Looking at each of your answers:

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

# Task 3
# attempt 1
", ".join(sundaes)  # Creates string using 'join' does not assign it to anything
menu.format(", ".join(sundaes))  # uses constructed string, but you need to assign to menu
# attempt 1 fix:
menu  = menu.format(", ".join(sundaes))  # assign to menu

# attempt 2
# OR whether I should name them?
sundaes = ", ".join(sundaes) # destroys sundaes value; fails task 1
menu = menu.format(sundaes) # correctly creates 'menu' but 'sundaes' is already destroyed
# attempt 2 fix, use intermediate value
sundaes_string = ", ".join(sundaes) # destroys sundaes value; fails task 1
menu = menu.format(sundaes_string) # correctly creates 'menu' but 'sundaes' is already destroyed

# attempt 3
# OR whether it should be written like this?
menu = menu.format(", ".join(sundaes))  # PASSES

# Attempt 3 passes for me!
Chase Frankenfeld
Chase Frankenfeld
6,137 Points

Thanks Chris Freeman. You are a legend.

I don't have a clue why it didn't work previously. Must have messed something up each time.

Cheers