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
Nataly Rifold12,431 Points
In the Dungeon Game video, why use remove and not pop?
So, why remove and not pop? I mean remove deletes a value (as I understand). So how come is doesn't delete permanently the removed value?
And why x, y = player and not player = x, y?
pop work differently.
removesearches for the argument provided within the list, and if it finds it, it will remove it. It returns nothing, and it only deletes the first find.
poptakes an index as a value, and "pops" the element at that index. It returns the element it popped. It doesn't search for the argument, as it directly takes in an index.
So I suppose in this case it is easier to use
remove instead of
player = x, y and
x, y = player, they are two completely different statements. (No, they don't do the same thing.) The first statement assigns
player to a tuple containing the values
(x, y). The second statement "unpacks"
player, and assigns each variable to the corresponding value in the tuple
player. For more info on unpacking, watch this video.
I hope this clears things up!