How do you set up a stack?

Nick Perkins nperkins7 at home.com
Wed May 9 02:05:33 EDT 2001


don't feel stupid, it was a good question.

if you are learning python, it's not such a bad exercise,
and 'print eval(f)' doesn't really help you learn much.

..to make a stack..

any list can be used as a stack:

>>> a = [1,2,3,4,5]
>>> a.pop()
5
>>> a
[1, 2, 3, 4]
>>> a.append(99)
>>> a
[1, 2, 3, 4, 99]


( note that 'append' is used as the 'push' function )
we just pretend that the list is a stack, with the
'top' of the stack at the end of the list.

you can use one or two stacks to evaluate simple expressions..
go ahead and give it a try..






More information about the Python-list mailing list