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 trialBrett Burky
3,895 PointsI am trying to get
full_name = "Brett Burky" name_list = full_name.split()
greeting_list = ["Hi, I\'m,["full_name"]"]
I am trying to get past the:Create a variable named greeting_list that's the string "Hi, I'm X" split on the spaces.
I got the part with the first question, but now I think that is breaking the second question.
I nested the one list in the other list but am still missing something.
9 Answers
Marko Koron
20,658 PointsRolling on the floor with a WTF face expression.... Just kidding, before the join part you have to replace the last item in greeting_list with your name then use join like this: greeting = ''.join(greeting_list).
Oh yeah, and use greeting_list = "Hi, I'm X".split() as Kristen suggested.
Marko Koron
20,658 PointsYou are completely off track. -Think of a method that Kenneth sometimes used after print()- (wrong!). Sorry is thought that you have to insert your name! lol. Actually is the same as the first question. Is there a strike through option like in HTML?
Kristen Law
16,244 PointsHey Brett! Looks like you're trying to create greeting_list
manually. It can be done this way, but you'll need to make sure you put each list item inside quotes since they are strings. In this task, it is literally asking for the string "Hi, I'm X". You don't need to use the variable full_name
yet.
See below:
greeting_list = ["Hi,", "I'm", "X"]
Alternatively, you could use the split
method for strings, just like you did in Task 1:
greeting_list = "Hi, I'm X".split()
Edit: Changed answer to properly reflect what is being asked in Task 2, as Marko pointed out below.
Marko Koron
20,658 PointsActually you need to replace the X with you name in task 3 (it fooled me also) just I didn't want to confuse Brett. But I checked, and you can pass the challenge this way also (guess you are one step ahead in task 3).
But... I think that giving the full solution, since it is an exercise after all, isn't the best solution. It is better to guide the person to it.
Kristen Law
16,244 PointsAh ok, good catch! Didn't look at task 3.
I learn better by seeing code with explanations. I guess each person is different.
Kenneth Love
Treehouse Guest TeacherHey Brett Burky! You definitely don't need to split the string manually, like your original code example. Use the .split()
method to break the string up. It splits the string on whitespace (spaces, tabs, new lines, etc) automatically, so you don't need to do anything special when you call it.
Brett Burky
3,895 PointsOk I think I'm driving myself nuts over here. First off I appreciate all of your help with this, it's such a new concept that I'm having some issues with it.
I have watched the videos over again and I am getting the ' 'join () and see that this is somehow playing into it. I have tried to put it into the greeting string, but am getting errors.
Here is what I got please let me know if I am close or if you're rolling on the floor like "WTF" how did he get to that :)
full_name = "Brett Burky" name_list = list(full_name.split()) greeting_list = "Hi, I'm 'name_list'".split() ' 'join.(greeting_list) greeting = "greeting_list"
Brett Burky
3,895 PointsThanks so much Marko, this is helping a lot I appreciate your time.
Marko Koron
20,658 PointsNah, don't worry mate. We are here to help each other. Oh, I just noticed that I haven't put a space between the commas before join so the result ends up being merged together.
Brett Burky
3,895 PointsI am going to have to pass on this one I have watched the video and I don't get it.
full_name = "Brett Burky"
name_list = full_name.split()
greeting_list = "Hi, I'm {full_name}".split()
greeting = .join(greeting_list)
http://cl.ly/image/0w0X0Y3t3z2p
I know you don't give away answers so if there is a way to send a private message that would work. I don't see it. I tried append. and I have watched the video a number of times.
Marko Koron
20,658 PointsCome on, I'm not that severe! :D It is just that I think that is better to guide someone to answer then give it straightaway.
full_name = "Brett Burky"
name_list = full_name.split()
#This is the correct phrase you should write.
greeting_list = "Hi, I'm X".split()
#Replace the last item in the list with full_name (you could also write greeting_list[2] = full_name, but with length - 1 you are sure that
# will address the last item).
greeting_list[len(greeting_list) - 1] = full_name
#Join the greeting_list in a string with a space between the words.
greeting = " ".join(greeting_list)
oops I used the """ syntax from Python :)
Kenneth Love
Treehouse Guest TeacherYou're amazingly close. You have your name and you split()
it into name_list
. And you figured out that you have to split
the "Hi, I'm X"
string, so good job there. Now you just have two steps left.
First, change the last item in greeting_list
to the first item in name_list
. You change things in lists by assigning new values to their indexes. greeting_list
has three things in it, in order. "Hi," "I'm", and, in your case, "{full_name}". Since indexes start at 0, "{full_name}" has an index of 2. So change greeting_list[2]
to be the correct new value which is the first item (index of 0) in name_list
.
Now comes the last step. You need to recombine everything in greeting_list
into a single string. There are a couple of ways you can do this. The long way would be to use concatenation and add each item together with spaces. Something like:
greeting = greeting_list[0] + " " + greeting_list[1] + " " + greeting_list[2]
I'm sure you see how repetitive this approach is. So, let's use the string method join
to combine all of these things. To use join
, we have to give it a string to put between each thing in the list. We want a space, so make a string with a space in it. " "
. Then use the join()
method exactly like you have above and you should have everything passing.
If you're still having problems, feel free to email me (kenneth@teamtreehouse.com) and I'll help you get this all down.
Marko Koron
20,658 PointsLol, when one waste time re-editing the answer to get the code part right you end up with two answers!
Charles Steinmetz
14,420 Pointsfull_name = "Han Solo"
name_list = full_name.split()
greeting_list = "Hi, I'm X".split()
greeting_list[len(greeting_list) - 1] = name_list[0]
greeting = " ".join(greeting_list)
print(greeting)