-
-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pop() instead of del in the Lists lesson? #618
Comments
Note: a change was made in the python-novice-inflammation lesson a few years ago to teach |
I think this is a quite reasonable suggestion, especially as the novice-inflammation lesson articulates well, staying consistent with list operations and methods as opposed to introducing a new language construct. I think a PR would be welcome, thanks for raising the issue! Thoughts from others & @vahtras ? |
Well it depends on the context. These are different use cases, and pop()
is for when you actually need to return the deleted value for something
else. Just del suffices for deletion. Maybe the computer science students
have some issue with syntax that does not look object-oriented? A quick
check on may laptop gives
>> timeit(stmt='foo=[1, 2, 3]; foo.pop(1)')
0.12092131999816047
>> timeit(stmt='foo=[1, 2, 3]; del foo[1]')
0.06836886899691308
i.e. pop is twice as slow in this case, even including object creation, not
that it matters much in practice. I don't have a strong preference for
either version (but I do object to students not doing as instructed...). We
could teach pop() but then there should be an exercise or example where it
makes sense, i.e. which uses the return value.
Olav
…On Fri, Nov 4, 2022 at 11:19 PM Allen Lee ***@***.***> wrote:
I think this is a quite reasonable suggestion, especially as the novice-inflammation
lesson
<swcarpentry/python-novice-inflammation#686>
articulates well, staying consistent with list operations and methods
<http://swcarpentry.github.io/python-novice-gapminder/11-lists/index.html#appending-items-to-a-list-lengthens-it>
as opposed to introducing a new language construct.
I think a PR would be welcome, thanks for raising the issue! Thoughts from
others & @vahtras <https://github.com/vahtras> ?
—
Reply to this email directly, view it on GitHub
<#618 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLLJBIH5OTYBEOTSEKSZR3WGWDWLANCNFSM6AAAAAARWTEYSA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
After a bit of googling I seem to understand that pop and del have the same computational complexity, and in fact pop is a wrapper around del. Therefore, we must not make it a question of runtime. I would tend to agree that pop is more elegant because it's a method of the list class. I don't have a strong preference either. |
I think this StackOverflow post articulates well the differences between the two and I like the answer as well: https://stackoverflow.com/questions/24547223/is-del-or-pop-preferred-when-removing-elements-from-dicts
|
Personally, I never use pop.
If somebody wants to add |
I can confirm this is the only place where del is explained. I would welcome adding a bit more explanation about it (e.g. in the earlier episode on variables, explain that you can delete a variable; or simply add a passing mention here in the lists episode, saying that it can be used on any variable). |
Hi team,
I teach this sequence every term as a free workshop at the library with the assistance of an undergraduate CS major. Thank you for all your hard work to build something that works so well. While I myself have no opinion on using
pop()
vsdel
in Python, every single undergraduate whom I've invited teach the Lists lesson has refused to teachdel
and instead taughtpop()
. This makes me think that there must be a strong preference in programming for usingpop()
, and that it would be of use to our students to follow convention. If, however, this convention is particular to the U of Oregon's Computer Science Department, I'm happy to withdraw the suggestion.If everyone agrees that
pop()
is the way to go, I'm happy to work with my students to make the PR.Gabriele
The text was updated successfully, but these errors were encountered: