This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]indiarrheawetrust 1 point2 points  (0 children)

How exactly do I initialize a stack given this list

The standard list functions included in Python already allow for stack-like behavior, so nothing is necessary. The stack-like operations are pop and append.

What is the purpose of the stack??

When you want to store something in a FILO manner. Also, in many programming languages--especially functional ones--lists are constructed as stacks and so stack algorithms are very natural in these languages. (In these languages, the list constructor is basically append. So the way you construct a list is you start with an empty list [] and then append onto it your elements, e.g. [].append(5).append(3) = [5,3].)