0

As far as I understand it, a python list

a = [0,1,2]

is similar to a stack.

So does this mean, that for a list b

 b[1]*b[2]

will be slower than

b[10001] * b[10002]

because it takes longer to get the elements at the bottom of the stack? Or is there more to a python list than a simple stack?

physicsGuy
  • 3,437
  • 3
  • 27
  • 35
  • 2
    Python doesn't iterate through the list to access elements. Related [Python List Indexing Efficiency](http://stackoverflow.com/q/11400163) – Bhargav Rao Jun 18 '16 at 16:17
  • Thanks, that's the answer to my question. – physicsGuy Jun 18 '16 at 16:20
  • Np, Marked as dupe. – Bhargav Rao Jun 18 '16 at 16:20
  • 1
    Where did you read that python list are stack ? Do you confused stack/heap memory allocation and the container called stack ? – Julien Goupy Jun 18 '16 at 16:22
  • Anyway, a stack is an abstract data type, which can be implemented using different underlying data structures, which will give different time complexities. – juanpa.arrivillaga Jun 18 '16 at 17:21
  • I did a python tutorial on queues and stacks. The solution was basically that Queues had to be coded on my own, but stacks are already implemented by python lists with list.pop(). That's why I was wondering if they are actually stacks. – physicsGuy Jun 19 '16 at 14:35

0 Answers0