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

Why is taco_joints.copy() used instead of taco_joints ?

I am quite confused... I understand that a copy must be made of a list when it is potentially modified or iterated through in a loop.

But why are there two copies made? taco_joints is a copy of restaurants, so why does there need to be a copy of the copy? If the code is repeated, won`t it reset everytime the program executes the line:

taco_joints = restaurants.copy()

If not, what am I missing here?

Thank you,

Tim

The full code for the question is:

all_restaurants = [ "Taco City", "Burgertown", "Tacovilla", "Hotdog station", "House of tacos", ]

def tacos_only(restaurants): taco_joints = restaurants.copy() for taco_joint in taco_joints.copy(): if "taco" not in taco_joint.lower(): taco_joints.remove(taco_joint) return taco_joints

dinner_options = tacos_only(all_restaurants)