Christopher Spears wrote:
I see what you mean. I have tested it, and I have gotten a weird result:
def shorten(lst):
... lst = lst[:-1]
...
lista = [1,2,3,4]
shorten(lista)
print lista
[1, 2, 3, 4]
lista = [1,2,3,4]
lista = lista[:-1]
print lista
[1, 2, 3]
Strange...why does it work o
On 18/07/2008, Christopher Spears <[EMAIL PROTECTED]> wrote:
> I see what you mean. I have tested it, and I have gotten a weird result:
>
> >>> def shorten(lst):
> ... lst = lst[:-1]
>
> ...
>
> >>> lista = [1,2,3,4]
> >>> shorten(lista)
> >>> print lista
> [1, 2, 3, 4]
[...]
> Strange...wh
"Christopher Spears" <[EMAIL PROTECTED]> wrote
I am almost done with a stack class that I wrote:
Some comments...
class Stack(list):
def isempty(self):
length = len(self)
if length == 0:
return True
else:
return False
This can just be
return bool(len(self)
>
> First, a tip:
>
> Instead of lista[:len(lista)-1], you can (and should) just
> write lista[:-1].
>
> Now, what if we wrap that in a function:
>
> >>> def shorten(lst):
> ... lst = lst[:-1] # identical to: lst =
> lst[:len(lst)-1]
> ...
>
> Then test it:
>
> >>> lista = [1, 2, 3, 4]
>
On 18/07/2008, Christopher Spears <[EMAIL PROTECTED]> wrote:
> How come the stack doesn't shrink when I pop off the last value? I tested
> the code in the interpreter:
>
> >>> lista = [1,2,3,4]
> >>> lista[:len(lista)-1]
> [1, 2, 3]
> >>> lista = lista[:len(lista)-1]
> >>> lista
> [1, 2, 3