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 Splitting and Joining

Priyansh Lakhotia
Priyansh Lakhotia
1,010 Points

objective 1 rejecting everything I write

the challenge is rejecting anything I write. how do I do it.

Steven Parker
Steven Parker
231,261 Points

Review the video to be sure you know the syntax for split. Then, if you still have trouble, post your code here so someone can help you fix it.

Priyansh Lakhotia
Priyansh Lakhotia
1,010 Points

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

this is my code. can anyone help me by telling what is wrong.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Priyansh Lakhotia

To post your code snippet, use the Markdown Cheatsheet. It has an example for reference of how to post code snippets.

It is located just below the text box you use to comment.

For code snippets:

  • place three backticks which look like this: `
  • right after the third backtick you can type the name of the language, in your case python
  • press ENTER then paste your code in
  • press ENTER then place three more backticks to close the code snippet

(backtick is located underneath the ESC button on your keyboard and above TAB)

If you do it correctly, your code snippets will come out readable like this. :-)

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

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Priyansh Lakhotia

You have the right idea, you just have them mixed up backwards.

The .split() method takes an input of the THING you want to split a string on.

available variable contains a long string with some characters acting as separators.

Since available contains a string, you can call .split() on that variable. But the split() needs to know out of that entire string, on what character/string should it break the string up at.

Im trying to lead you to the answer without giving you it :-)

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

A Similar Example:

long_string = "some_really_long_string_that_needs_to_be_broken_up"
broken_up = long_string.split('_')

# Output of broken_up would be
#
# ['some', 'really', 'long', 'string', 'that', 'needs', 'to', 'be', 'broken', 'up']