[Tutor] changing list element in loop

Jim Mooney cybervigilante at gmail.com
Sat Apr 27 11:49:52 CEST 2013


Why isn't 'e' changing to 'pP here when the vowel list is mutable:

vowelList = list('aeiouy')

for x in vowelList:
    if x == 'e':
        x = 'P'

print(vowelList)

#result: ['a', 'e', 'i', 'o', 'u', 'y']

--
Jim Mooney


More information about the Tutor mailing list