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)
![Bruno Correia](https://uploads.teamtreehouse.com/production/profile-photos/8149362/micro_profile_pic.jpg)
Bruno Correia
3,114 PointsWhy is "sword" and "boomerang" left when deleting while iterating?
So I understand that to be able to delete all items on the list, we need to make a copy of the list so all items are actually deleted. I don't quite understand why, however. What makes the following not work as we expect it to? Looking at the code, as Craig said, it makes total sense to do it like this. What causes it not to work?
for item in inventory:
inventory.remove(item)
2 Answers
![ct9](https://secure.gravatar.com/avatar/1775ac8b29254eea32ddf586a43296f3?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ct9
11,778 PointsSimilar question is already answered here: https://teamtreehouse.com/community/why-doesnt-listremove-removes-all-the-elements-after-using-a-for-in-loop-but-using-loop-in-for-listcopy-does
If you are still in doubt, ask in comments. I will surely try to help you.
![Bruno Correia](https://uploads.teamtreehouse.com/production/profile-photos/8149362/micro_profile_pic.jpg)
Bruno Correia
3,114 PointsOhh, thank you! I promise I tried to search first but missed that one somehow :-P The reply there was very helpful, thank you for pointing it out