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)
![David Dong](https://uploads.teamtreehouse.com/production/profile-photos/5220662/micro_imgres.jpg)
David Dong
5,593 PointsWhy wasn't wishes[0] used instead of wishes.pop(0)?
.pop(0) removes an item from the list, but wishes[0] doesn't. He ended up copying the list, but why not just use wishes[0] instead?
1 Answer
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsGood question! Since the parameter wishes
is mutable (changeable) list, by using .pop()
it modifies the contents of the list seen outside of the function call. This “side effect” might not be desirable. My making a copy, this prevents changing the list seen outside of the function.
As for why pop(0)
vs [0]
, the desire is to suggest the first item in the list then display the remainder of the list. This could also have been accomplished without using the copy:
suggested_gift = wishes[0]
for wish in wishes[1:]:
by using the wishes[1:]
slice, a copy is automatically created.
Post back if you need more help. Good luck!!!