[Tutor] Replacement of items in a list

VanL vlindberg@verio.net
Fri, 03 Aug 2001 12:30:52 -0600


Why is this?

:::::::::::::: Begin test.py

#!/usr/bin/env python

import string

lst = ['ONE', 'TWO', 'THREE']
lst1 = lst[:]
lst2 = lst[:]

def replace1(list):
    """ Uses item replacement"""
    for x in list:
        x = string.lower(x)

def replace2(list):
    """Uses position replacement"""
    for x in range(len(list)):
        list[x] = string.lower(list[x])


:::::::: Begin Interpreter Session

 >>> from test import *
 >>> dir()
['__builtins__', '__doc__'
ace2', 'string']
 >>> lst1
['ONE', 'TWO', 'THREE']
 >>> lst2
['ONE', 'TWO', 'THREE']
 >>> replace1(lst1)
 >>> replace2(lst2)
 >>> lst1
['ONE', 'TWO', 'THREE']
 >>> lst2
['one', 'two', 'three']