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

Heath Kirchner
Heath Kirchner
613 Points

Not sure how to get task 3 of 3 of .split() and .join() to work. Would help if there were examples to work off of.

Everytime I attempt to do this task, and get it wrong, I have to start over becasue task 1 will no longer solve. I am not sure what I am doing because the video did not really cover this and there are no examples to look over.

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

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

1 Answer

cm21
cm21
150,854 Points

Hi Heath,

You're halfway there. The challenge wants us to add this new string information onto the menu variable's current value. Thus:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu = "Our available flavors are: {}".format(', '.join(sundaes))
  • The sundaes variable is used as an argument that is passed to the join method.
  • The format method is used to specify how we want the text to be formatted (we're telling the format method "hey, replace that {} placeholder with our sundaes, and separate each one with a comma and a space.")

Hope this helps!