Add "default" kwarg to list.pop()
30 Oct
2018
30 Oct
'18
11:44 p.m.
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) 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: https://github.com/giampaolo/psutil/issues/1354#issuecomment-434495870 https://github.com/giampaolo/psutil/blob/d8b05151e65f9348aff9b58da977abd8cac... 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. Thoughts? -- Giampaolo - http://grodola.blogspot.com
1987
Age (days ago)
1997
Last active (days ago)
41 comments
18 participants
participants (18)
-
Abe Dillon
-
Anders Hovmöller
-
Antoine Pitrou
-
Chris Angelico
-
Chris Barker
-
Dan Sommers
-
Eric Fahlgren
-
Ethan Furman
-
Giampaolo Rodola'
-
INADA Naoki
-
Michael Selik
-
Michel Desmoulin
-
Nick Timkovich
-
Nicolas Rolin
-
Robert Vanden Eynde
-
Ron Reiter
-
Serhiy Storchaka
-
Steven D'Aprano