[Python-ideas] Add "default" kwarg to list.pop()

Nick Timkovich prometheus235 at gmail.com
Thu Nov 1 21:57:15 EDT 2018


Does it make sense to draw some sort of parallel between next(myiterator,
default="whatever") and mylist.pop(default="whatever")? They exhaust the
iterator/list then start emitting the default argument (if provided).

On Thu, Nov 1, 2018 at 2:46 PM Serhiy Storchaka <storchaka at gmail.com> wrote:

> 31.10.18 13:08, Antoine Pitrou пише:
> > +1 from me.  dict.pop() already has an optional default.  This is a
> > straight-forward improvement to the API and no Python programmer will
> > be surprised.
>
> list.pop() corresponds two dict methods. With argument it corresponds
> dict.pop(). But there are differences: dict.pop() called repeatedly with
> the same key will raise an error (or return the default), while
> list.pop() will likely return other item. Without argument it
> corresponds dict.popitem() which doesn't have an optional default.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181101/a88790fd/attachment-0001.html>


More information about the Python-ideas mailing list