473,416 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

A Q. on pop().

Hi,
The code.

def buildStackMajor():
for node in dirStackMinor:
#print 's is the node...', node
dirStackMajor.append(node)
dirStackMinor.pop()
print 'POP the stack...', len(dirStackMinor)
print 'after pop...', dirStackMinor

When I start the "for" loop I have 11 members in
the stack- a list. The pop() is poping member
from the back, as though it's deal with a LIFO
stack instead of LIFO. I never get pass a length
of 5.
first Q.. Why is pop() starting from the back
back of the stack?
second Q.. Why can't I never empty the stack?
Thanks.

Jul 18 '05 #1
1 2232
spencer wrote:
first Q.. Why is pop() starting from the back
back of the stack?
Because that is what it does. Try reading the documentation:
help(list.pop)

Help on method_descriptor:

pop(...)
L.pop([index]) -> item -- remove and return item at index (default
last)

second Q.. Why can't I never empty the stack?


Because you are modifying a list while iterating over it which is never a
good idea. What you have now pops items from the end of the loop so it
stops about half way along. If you change it to pop item 0 then it will
shift the items down and your iteration will end up skipping over about
half of them.

Try something like this:

def buildStackMajor():
while dirStackMinor:
dirStackMajor.append(dirStackMinor.pop(0))

although in that case you might just as well get rid of the loop entirely:

dirStackMajor += dirStackMinor
del dirStackMinor[:]
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Will | last post by:
Hi, Sorry to be a pest... But I can figure this out. I'm pushing to a stack. then I need to check to see if the word is a palindrome. Is the code below correct? if so, how can I check the...
53
by: Bill | last post by:
Hello Programmers, I am looking for either Java Script (OR HTML etc) to DEFEAT Pop-up Stoppers e.g It will bring up a window that will LOOK like a Pop-up FEEL like a Pop-up Allow a name and...
23
by: David McCulloch | last post by:
QUESTION-1: How can I detect if Norton Internet Security is blocking pop-ups? QUESTION-2a: How could I know if a particular JavaScript function has been declared? QUESTION-2b: How could I...
18
by: Mickey Segal | last post by:
On comp.lang.java.programmer we are discussing problems created for Java programs by pop-up blockers (in the thread "showDocument blocked by new microsoft pop-up blocker"). Our problem is that...
4
by: nsr93 | last post by:
I am not sure if this was the proper group to post this, but here is my question: I am a Java consultant. I have new client I am working for to make a web based application similar to an...
10
by: Madame Blablavatsky | last post by:
hello, i have a few links on a page. when one clicks a link an pop up window with an image opens. when people click an other link i want the already availible pop up window to close before the...
3
by: JohnEGee | last post by:
Hello, all, and TIA for any help you can offer. I've searched the Internet for answers and have finally come here. I've created a page (several, actually) with a link that opens a pop-up...
2
by: domtam | last post by:
Hi all, Here is what I want: when a user clicks a <asp:button>, its event handler will do some server-side processing and then pop up a windows of another page. As far as I know, if no pop-up...
25
by: Nicholas Parsons | last post by:
Howdy Folks, I was just playing around in IDLE at the interactive prompt and typed in dir({}) for the fun of it. I was quite surprised to see a pop method defined there. I mean is that a...
7
by: Scott | last post by:
As said before I'm new to programming, and I need in depth explaination to understand everything the way I want to know it, call it a personality quirk ;p. With pop() you remove the last element...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.