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

Python Python Basics (Retired) Shopping List Lists and Strings

Joshua Wassing
Joshua Wassing
2,069 Points

How am I supposed to make my 'name_list's first item replace 'greeting_list's item that has the value of 'Treehouse'?

I think I am approaching it from the wrong way, but it seems to make sense the way I currently have it. How I've written it, the 'greeting_list' item on the 3rd index (Treehouse) should be getting replaced by the first item of 'name_list'. Am I missing Something?

greeting_list.py
full_name = "Joshua Wassing"
name_list = list(full_name.split())
greeting_list = list("Hi, I'm a Treehouse".split())
greeting_list[3] = name_list[0]

4 Answers

Max Hirsh
Max Hirsh
16,773 Points

Remember that in programming, indexing starts at 0 and goes up from there. You are on the right track though!

rydavim
rydavim
18,813 Points

Welcome to Treehouse!

You have the right idea, and there's nothing really 'wrong' with your code. However, challenges want very specific things usually. In this case, I think the problem is that you've added an 'a' into their given sentence. I think if you remove that, and change the index value accordingly, you should be good to go.

full_name = "Joshua Wassing"
name_list = list(full_name.split())
greeting_list = list("Hi, I'm Treehouse".split()) # removed an 'a'
greeting_list[2] = name_list[0] # changed index value to 2 due to removal
Max Hirsh
Max Hirsh
16,773 Points

Hi there, are we allowed to give the answer in forum replies now?

rydavim
rydavim
18,813 Points

mh42 - Generally posting stand-alone answers, or posting solutions without any explanation is frowned upon. However, I don't believe there's any reason not to post valid code, as long as you're not negatively impacting another student's learning.

In this case, the original code is already selecting by index correctly. However, the challenge wants very specific strings, so adding words can cause problems even if the code concepts are correct.

I don't think you should feel like you 'can't' ever post code examples, just make sure that you're explaining what you're doing. Thank you for participating in the forums!

Max Hirsh
Max Hirsh
16,773 Points

Ok great, good to know, thanks!

Joshua Wassing
Joshua Wassing
2,069 Points

Ah, was able to see my mistake. Thanks for the help everybody!

Hi Joshua

Just one thing i thought i would mention. I notice that you are converting full_name.split() to a list like so list(full_name.split()). This is not required as the split method when called on the string class creates a list for you, it splits on spaces unless you specify another delimeter.

so the same code code have been written like this.

full_name = "Joshua Wassing"
name_list = full_name.split()
greeting_list = "Hi, I'm Treehouse".split() # removed an 'a'
greeting_list[2] = name_list[0] # changed index value to 2 due to removal