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 trialtea kokot klancnik
119 Pointssplit list on the spaces
how to split Hi, i'm Treehouse on spaces?
full_name='Tea Kokot Klancnik'
name_list=['Tea', 'Kokot', 'Klancnik']
4 Answers
Tyrell Jentink
8,415 PointsYou are looking for the .split() method:
full_name='Tea Kokot Klancnik'
name_list= full_name.split(' ')
Anish Walawalkar
8,534 Pointsyou can use the .split() method. you can specify what you want to split the string on. In your chase you want to split on spaces:
full_name = 'Tea Kokot Klancnik'
name_list = full_name.split(' ')
say you wanted to to split on commas (,) then
full_name = 'John, Doe, April, Adams'
name_list = full_name.split(',')
Nitin George Cherian
4,410 PointsIf you want to split on spaces, just use
full_name.split() # No arguments for split method
If no argument are specified, it splits by space by default
Sai Kiran Dasika
Courses Plus Student 7,278 PointsIf you want to split on spaces you can just use this code.
a_string = "this is a string"
a_string = a_string.split(' ')
This will produce a result of
["this", "is", "a", "string"]