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 Introducing Lists Using Lists Review Split and Join

I'm not super clear on the wording here. I get the question, but I don't quite understand the answers available.

We have a list and we want to make it a string... so we split the string. so I'd do option B 'split. It's on a string'.

2 Answers

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

You use join to put list entries together into a string and use split to break out a string into list entries.

Try messing with this:

string_example = 'this is a string'

print('string example is --> ', string_example)

list_from_string = string_example.split()

print('split on whitespace to get list from string --> ', list_from_string)

string_from_list = ' sep '.join(list_from_string)

print('join to get string from list --> ', string_from_list)

another_list_from_string = list(string_example)

print('every item of iterable as list entry --> ', another_list_from_string)
# output
string example is -->  this is a string
split on whitespace to get list from string -->  ['this', 'is', 'a', 'string']
join to get string from list -->  this sep is sep a sep string
every item of iterable as list entry -->  ['t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g']

:tropical_drink: :palm_tree:

Thanks 🙏