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 (2015) Shopping List App Second Shopping List App

mohammed abdi abdulahi warsame
mohammed abdi abdulahi warsame
4,926 Points

wrote the code in different way

The teacher wrote the code like this:

def Show_list():
print("heres is your list")
for item in shoping_list:
    print(item)

and i done it this way and it's working! what do u guys things:

def Show_section(): print("you Have in your list:") print(shopping_list)

1 Answer

Steven Parker
Steven Parker
229,783 Points

That might work for printing.

But there are other reasons you might want to iterate through a list, and the method shown in the video gives you an opportunity to practice the iteration.

mohammed abdi abdulahi warsame
mohammed abdi abdulahi warsame
4,926 Points

what is the other reasons!?, i thought that as long there is no erors its ok

Steven Parker
Steven Parker
229,783 Points

Another reason for iterating a list might be to search for a specific element, comparing each one to some value. Or you might be collecting statistics of some kind (like "how many entries start with 'm'?").