On 04/09/10 06:54, M. Hamed wrote:
> Thanks Patrick, that is what I was exactly looking for.
> 
> Paul, thanks for your example. wasn't familiar with the stack class. 

The stack class is nothing but a wrapper that renames append() to
push(); everything you need can be fulfilled by the regular list.

> I feel Patrick's method is a lot simpler for my purpose.

No you don't.

>> Well, if you never want to add intermediate data between your new
>> element and the stack, you can just do:
>>
>> stack[index:index + 1] = [newelement]

that is effectively the same as:

stack.insert(index, newelement)

But if you really want to use list as a stack, you don't want to manage
your stack pointer manually; let `list` manage the stack pointer for you
and use .append() and .pop()
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to