Python Forum
mutable_sequence.pop() documentation
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mutable_sequence.pop() documentation
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
I'd have to see a real example.
Reply
#5
(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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
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]
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020