[Python-ideas] Add "default" kwarg to list.pop()
desmoulinmichel at gmail.com
Wed Oct 31 07:11:23 EDT 2018
+1 one this.
And a list.get method has well, with a default value.
Le 31/10/2018 à 00:44, Giampaolo Rodola' a écrit :
> Sorry in advance if this has been proposed in the past but I couldn't
> find anything on python-ideas:
> >>> l = 
> >>> l.pop(default=1)
> FWIW my use case consists in reading entries from /proc/diskstats where
> lines can have a variable number of fields depending on the kernel version:
> As such it would be convenient to set missing fields to 0 as "reads =
> fields.pop(default=0)" instead of catching IndexError every time. Extra:
> for consistency set.pop() should probably have the same.
> Giampaolo - http://grodola.blogspot.com
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas