Skip to content
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

Open
gabrielesh opened this issue Nov 3, 2022 · 7 comments
Open

Use pop() instead of del in the Lists lesson? #618

gabrielesh opened this issue Nov 3, 2022 · 7 comments
Labels
type:enhancement Propose enhancement to the lesson

Comments

@gabrielesh
Copy link

gabrielesh commented Nov 3, 2022

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() vs del in Python, every single undergraduate whom I've invited teach the Lists lesson has refused to teach del and instead taught pop(). This makes me think that there must be a strong preference in programming for using pop(), 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

@ldko
Copy link

ldko commented Nov 4, 2022

Note: a change was made in the python-novice-inflammation lesson a few years ago to teach pop instead of del.

@alee
Copy link
Member

alee commented Nov 4, 2022

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 ?

@alee alee added the type:enhancement Propose enhancement to the lesson label Nov 4, 2022
@vahtras
Copy link
Contributor

vahtras commented Nov 8, 2022 via email

@martinosorb
Copy link
Contributor

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.
On the other hand, del works with multiple elements (e.g. del lst[2:5]).

I don't have a strong preference either.

@alee
Copy link
Member

alee commented Jul 5, 2023

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

del makes it clear you are only interested in removing the thing from the list. Use pop when you care about using the thing you are removing from the list (that you are treating as a stack). So... that probably still doesn't bring clarity as to whether we should teach one or the other. Maybe both?? 👀

@martinosorb
Copy link
Contributor

martinosorb commented Jul 24, 2023

Personally, I never use pop.

del should definitely be taught somewhere in the lesson. Is it explained anywhere else? I wouldn't remove it from here unless it is.

If somebody wants to add pop alongside I have no problem with it.

@martinosorb
Copy link
Contributor

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Propose enhancement to the lesson
Projects
None yet
5 participants