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 trialAddie Prinz
522 Pointshow do I replace a word in a variable?
I am trying to do the challenge task 3 for the shopping list. I am trying to replace Treehouse with my name
full_name = "Addie Mee Hee Prinz"
name_list = full_name.split(" ")
greeting_list = "Hi, I'm Treehouse".split(" ")
greeting_list[3] = full_name[0]
2 Answers
Orestis Pouliasis
5,561 PointsHere you go:
full_name = "Addie Prinz"
name_list = full_name.split()
greeting_list = "Hi, I'm Treehouse".split()
greeting_list[2] = name_list[0]
Joshua Ferdaszewski
12,716 Pointslists indexes start at 0. This can be tricky. Sometimes I find it helpful to write out the index for each element in a list. Use the Python interpreter to test out your code and pay close attention to the index of "Treehouse" and then take another look at this line of code: greeting_list[3] = full_name[0]
One other note, I don't remember this exact challenge, but you may be able to directly insert your name into the greeting_list
string when you create it. The .format()
method is very useful!
I hope that helps guide you in the correct direction (without giving away the answer ;), but if you have any other questions, ask away! I would love to help out. Good luck leaning Python!