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 trialmonroe swensen
766 Pointssrt.join
how do i get it to join
str = " "
full_name = "monroe swensen"
name_list = str.split(full_name)
greeting_list = str.split("Hi, I'm Treehouse")
greeting_list[2] = name_list[0]
greeting = str.join(greeting_list)
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsLet's look at how to improve your code.
# str = " " #<-- Don't use built-in function names as variables renaming
full_name = "monroe swensen"
#name_list = str.split(full_name) # <-- syntax reversed
name_list = full_name.split() # Split on white space
#greeting_list = str.split("Hi, I'm Treehouse") # <-- syntax reversed
greeting_list = "Hi, I'm Treehouse".split() # Split on white space
greeting_list[2] = name_list[0]
greeting = " ".join(greeting_list) # <-- variable not needed.
Michael Pastran
4,727 PointsMichael Pastran
4,727 Pointsthe reason why your code is failing is the str variable you created. the instructions say that you want to create a list separated on the whitespaces. so when you are trying to call the index on your name_list and greeting_list there are no index, because you never made it into a list. also for the joining them part. remember that you have to tell it where you will be joining them. so in this case you are joining them at the spaces so you write " ".join(greeting_list)
let me know if any of this is still confusing. i think what messed you up the most was that you didn't turn your name into a list so there was no way to use indexes