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
Renee Rhodes
10,653 PointsGreeting list code challenge
I'm doing something wrong here, more, I'm sure than the stray or missing characters that have seemed to plague my previous questions. I've gone back over the videos a couple of times, and I think i'm closer than I was, but I just can't quite seem to get how to put the third part together- i understand the concepts when they're in the videos and i'm following along and typing the same bit of code, but it just doesn't seem to be clicking when I'm not following along. It's a little frustrating, and I don't like that I have to keep stopping to ask questions at every single turn.
I could really use some suggestions on what to do to better understand this when I don't have pre-exisitng code to follow along with?
In the meantime, this is what I have:
'''full_name = "Renee Rhodes" name_list = "Renee Rhodes".split() greeting_list = "Hi, I'm Renee".split() greeting = " .join(greeting_list)"'''
6 Answers
Stone Preston
42,016 Pointsyou are very close. task 1 states: Create a variable named full_name that holds your full name. Make another variable named name_list that holds your full name as a list, split on the spaces. Don't create name_list manually!
so you did
full_name = "Renee Rhodes"
name_list = "Renee Rhodes".split()
which works but its actually probably better to reference the full_name variable in the second line:
full_name = "Renee Rhodes"
name_list = full_name.split()
task 2 states: Create a variable named greeting_list that's the string "Hi, I'm X" split on the spaces.
so you used:
greeting_list = "Hi, I'm Renee".split()
which is correct. the split method splits on spaces by default.
task 3 states: Lastly, change the last item in greeting_list to the first item in your name_list variable. Then join this list back into a string and store it in the variable greeting. You should end up with greeting containing "Hi, I'm <your first name>".
so first you need assign the first item in the name_list to the last item in the greeting list. to get the last item in greeting list, use the length of the list - 1 as the index. then to assign that item the first item in name list use index 0 of name list.
greeting_list[len(greeting_list) - 1] = name_list[0]
then we just need to join that string using the join function. to use the join function you call the join function on a string you want to use as the separator between list items and pass in the list as the argument of the function.
greeting = " ".join(greeting_list)
which joins the list together with a space between each item of the list.
the complete script looks something like this:
full_name = "Renee Rhodes"
name_list = full_name.split()
greeting_list = "Hi, I'm Renee".split()
greeting_list[len(greeting_list) - 1] = name_list[0]
greeting = " ".join(greeting_list)
Renee Rhodes
10,653 PointsWow....thanks. I never would have put that together from the information in the videos.
Kenneth Love
Treehouse Guest TeacherMind sending me an email with what you feel like the videos are missing?
Thanks for the info!
Renee Rhodes
10,653 PointsI emailed you, thanks!!
greyghost19
471 PointsI also had trouble with this one. I don't think I would have gotten it unless I found this question. So far I am loving team tree house and I plan to buy the service after the trial ends because I am highly motivated to learn this but as someone new to coding I feel like the last few lessons have been a huge jump in skill. Maybe it's just me but I have struggled with the challenges.
Thanks to the original poster for asking the question. Thanks also for the teachers who take the time to answer our questions.
Zach Katkin
1,566 PointsThanks Stone, this was incredibly helpful, but completely agree Renee, I feel like the reverse might be helpful - explain this step by step in terms of the video(s) and parts of videos. Just to confirm in plain language:
On the 4th line above - greeting_list is now a list (via split) - with the last item being "RENEE" - the "len" and "-1" are saying "take this last item in the list" and then the = name_list[0] sets it to the "RENEE" as defined in full_name?
Tejan Grabus
1,491 PointsI'm Stuck in this challenge. I spent the entire day trying to solve it but I couldn't. I tried the solution written above but still get wrong answer!
full_name = "Maxim Millen" name_list = full_name.split() greeting_list = "Hi, I'm X".split() greeting_list = [len(greeting_list) - 1] = name_list[0] <--- by adding this line shouldn't the variable greeting_list changes?? greeting = " ".join(greeting_list)
Steve Linn
11,841 Pointsdude, this seems to be an incredibly complex problem for the beginner stages…I'm confused if I am supposed to manually change the X in greeting_list or via python….
Kenneth Love
Treehouse Guest TeacherWell, once you've made the list, is there any difference between changing it with python or manually? Either way, the list is updated and correct.
Rafi Gilman
629 PointsHello, i was wondering why the method: name_list.insert("Treehouse") wont do the trick?
deronholmes
7,389 Pointsderonholmes
7,389 PointsThis line of code should work but it doesn't pass for some reason: