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 trialMUZ141004 Anna Makarudze
3,394 PointsHow do you rearrange words in a list so that the last word is the first word in Python?
I need Treehouse to be the first word in the list, for now it is the third and last word.
full_name = "Anna Makarudze"
name_list = []
name_list = ["Anna", "Makarudze"]
' '.join(name_list)
greeting_list = list()
greeting = "Hi, I'm Treehouse"
greeting_list = greeting.split()
print(greeting_list)
MUZ141004 Anna Makarudze
3,394 PointsThanks Ronald, it worked.
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsHi Anna, your code works for the first two challenges, but is violating the spirit of the challenge.
# Create a variable named full_name that holds your full name
full_name = "Anna Makarudze"
# Make another variable named name_list that holds your full name as a list, split on the spaces
# name_list = [] #<-- initialization not needed
# Your are creating the name list explicitly
# name_list = ["Anna", "Makarudze"]
# to create by splitting on spaces, use the same technique you used on greeting_list:
name_list = full_name.split()
# greeting_list = list() #<-- initialization not needed
# greeting = "Hi, I'm Treehouse" #<-- this is solution for task 4
greeting_list = "Hi, I'm Treehouse".split() #<-- split string directly
# replace "Treehouse" with your first name
greeting_list[2] = name_list[0]
# join greeting_list back into a string, separated by spaces
greeting = ' '.join(greeting_list)
# print(greeting_list) #<-- print not needed
MUZ141004 Anna Makarudze
3,394 PointsThanks Chris for the feedback. It was really helpful to me as new Python programmer.
MUZ141005 Ronald Maravanyika
3,148 PointsMUZ141005 Ronald Maravanyika
3,148 PointsAnna use the position of the word in the list. greeting_list[2]=name_list[0]
i think this will do the trick