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

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

how to do challenge task 4 ,stage 4 shopping list

Thank for answer the question Why another people don't need to use the () when write some thing

greeting_list.py
full_name = ("Thanitsak Leuangsupornpong")
name_list = (full_name.split())
greeting_list = list("Hi, I'm Thanitsak Leuangsupornpong".split()) 
greeting = (greeting_list "Hi, I'm Thanitsak")
 # use the format() method as well as the join() method

greeting_list  = "Hi, I'm {}".format(name_list[0]).split()
greeting = ' '.join(greeting_list) # am joining the list back into a string

# i hope i helped you remember to upvote me :)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hi Thanitsak,

The parens are optional in many cases. They can be useful when needing to wrap a line of code that does not fit on a single line due to length, or when you need to group arguments for logic or math equations. See Python Style Guide - PEP 8 for various parens usage. Also note the many cases where they are not needed.

I've put a solution for Task 4 in the code below:

# Your original code:
full_name = ("Thanitsak Leuangsupornpong")
name_list = (full_name.split())
greeting_list = list("Hi, I'm Thanitsak Leuangsupornpong".split()) 
# this line has syntax error:
# greeting = (greeting_list "Hi, I'm Thanitsak")

# Task 1 creates full_name and name_list
# Minor updates to your code.  Parens not needed.
full_name = "Thanitsak Leuangsupornpong" # <-- wrapping parens not needed
name_list = full_name.split() # <-- wrapping parens not needed

# Task 2 creates greeting_list
# Minor update to your code. split() returns list. list() wrapper not needed.
greeting_list = "Hi, I'm Treehouse".split()
#123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.

# Task 3 is asking to replace "Treehouse" with your first name only
# "Treehouse" is referenced using greeting_list[2]
#  Your first name value is referenced using name_list[0]
#  Assigning your first name to the index of "Treehouse" can be done this way:
greeting_list[2] = name_list[0]

# Task 4 is asking to rejoin list.  Best to use the str.join() method:
greeting = " ".join(greeting_list)