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 Index

Mayank Munjal
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Mayank Munjal
Front End Web Development Techdegree Graduate 18,120 Points

Why do we need to split the string to create a list when we can just use the command list('string')?

As seen in this video regarding indexes, alpha_list = list(alpha) when alpha = 'abcde'.

1 Answer

Hey, check my code for examples:

>>> string = "This is a string"
>>> list(string)
['T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g']
>>> 
>>> string.split(" ")
['This', 'is', 'a', 'string']
>>> 

Hope that helps!

If you have any other questions I will update my answer, if you do not have any other questions:

Remember to upvote and to choose the best answer so that your question receives a checkmark in forums.

Kind regards,

Leo