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

dalraemurray
dalraemurray
442 Points

Stuck joining a list into a string and storing it in a new variable for greeting_list.py

Script so far but I don't know how to join this list back into a string and store it in the variable 'greeing', ending up w/ 'greeting' containing "Hi, I'm <your first name>".

full_name = "Dal Mister"
name_list = "Dal Mister".split()
print name_list
greeting_list = "Hi, I'm X".split()
print greeting_list

greeting_list.remove(greeting_list[2])

greeting_list.append(name_list[0])

for item in greeting_list:
    print (item + " ")

2 Answers

Jegnesh Gehlot
Jegnesh Gehlot
5,452 Points

Hi dalraemurray , In order to complete this problem you have to store the string in a new variable. According to your code you are printing the items on the screen one at a time. Here is the code

full_name = "Dal Mister"

name_list = "Dal Mister".split()
print name_list
greeting_list = "Hi, I'm X".split()
print greeting_list
greeting_list.remove(greeting_list[2])
greeting_list.append(name_list[0])
result='' " #creating a new variable
for item in greeting_list:
    result=result+item+" " #storing the item in the result
print result #If the above logic is part of a function and you want to return the value then use "return result" instead of print result
dalraemurray
dalraemurray
442 Points

Thanks! I actually figured it out right after posting this. Could't find a way to remove my post. Is there a way?

Jegnesh Gehlot
Jegnesh Gehlot
5,452 Points

It looks like USER ID with Staff and Moderator next to them can delete the thread. Here is a relevant thread:

https://teamtreehouse.com/forum/deleting-posts-on-forum

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

We typically don't delete posts, especially when they might be the same issue that someone else runs into.