Python Forum

Full Version: mutable_sequence.pop() documentation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
the documentation for the .pop() method for mutable sequences says that the argument to be passed to it is a number in a list.  why is that?
That "list" notation is common for indicating that it's optional. So you provide either a number, or nothing.

Other readers can see https://docs.python.org/3.7/tutorial/dat...tures.html for an example.
so [[]] can mean an optional empty list. or for more fun [[n]] can mean an optional list with n as its only member or a list that can optionally have a member n or be empty.
I'd have to see a real example.
(May-18-2017, 03:48 AM)micseydel Wrote: [ -> ]I'd have to see a real example.

how would i do that?  i'm just making mixed interpretation of [] ehen there are two of them, one interpreted as a list spec and the other meaning optional.
You pop(index) out of the sequence

>>> l = list(range(1, 21))

>>> l
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

>>> for index, _ in enumerate(l):
...     print(l.pop(index+1))
2
4
6
8
10
12
14
16
18
20

>>> l
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]