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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Stefan Borghesani](https://secure.gravatar.com/avatar/2f6c8b221eecc3e5ae84b21e34d2368d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Stefan Borghesani
1,402 PointsDifferent way to accomplish the show_list function?
This is how I handled the show_list function:
def show_list():
show_list = "\n".join(shopping_list)
print("Here is your list: \n{}".format(show_list))
This seems to work exactly the same way. Is there any benefit to using a for loop as opposed to just printing the list with some formatting?
2 Answers
![Charlie Bird](https://secure.gravatar.com/avatar/18b7f2bfdc53fa76ad7b50ef3acb8d9d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Charlie Bird
7,277 PointsIn this case the result is the same, it's up to you how you choose to format your output.
The use of a for
loop may help in other instances where you want something to happen for each item in the list, e.g. you might want to add the items to another list or add up prices.
![Piotr Manczak](https://uploads.teamtreehouse.com/production/profile-photos/10607994/micro_20200829_211123.jpg)
Piotr Manczak
Front End Web Development Techdegree Graduate 29,253 PointsI did something similar:
def show_list(list): lista = ", ".join(list) + "." print("Your shopping list: {}".format(lista))