Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using a list as a stack
#5
but .pop() only works from the right end ("Remove and return an element from the right side of the deque."). there is also .popleft() for the other end. it is therefore not usable for the step of taking a reference from wherever it is in the deque and putting on an end (the chosen end to represent most recently used items). yes, .pop() can easily be O(1) because it does not need to search for what it wants to move from the middle of deque. but .remove(value) has to find value, which not an O(1) operation (you knew that). the documentation does not say if .remove(value) returns the item. but that is not an issue right now since the value is already had and i can .append(value) or .appendleft(value) it after .remove(value).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
using a list as a stack - by Skaperen - Feb-25-2019, 06:28 AM
RE: using a list as a stack - by woooee - Feb-25-2019, 06:32 AM
RE: using a list as a stack - by Skaperen - Feb-25-2019, 07:41 PM
RE: using a list as a stack - by buran - Feb-25-2019, 07:26 AM
RE: using a list as a stack - by Skaperen - Feb-25-2019, 08:43 PM
RE: using a list as a stack - by buran - Feb-25-2019, 08:46 PM
RE: using a list as a stack - by Skaperen - Feb-25-2019, 09:25 PM

Forum Jump:

User Panel Messages

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