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 outside of the function but not in it? Let me try
something else:
def shorten(lst):
... lst = lst[:-1]
Perhaps it would be helpful to consider the following...
def shorten1(lst):
lst[:] = lst[:-1]
... or ...
def shorten2(lst):
lst.pop()
Why might these exhibit different behavior?
HTH,
Marty
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor