On 27/04/13 10:49, Jim Mooney wrote:
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'
x is just a reference to the object in the list.
When you assign 'P' to x you are making x point at
a new
Oh, and another thing...
On 27/04/13 20:31, Jim Mooney wrote:
What's the simplest way to go through a list, find
something, and replace it with something else?
The simplest way is not to do it at all. Instead, create a new list:
vowels = 'aeiouy'
result = []
for char in vowels:
if char
On 27/04/13 20:31, Jim Mooney wrote:
Okay, I tried enumerate, but now I get an "immutable" error. So let's
turn this around since it's getting out of hand for a simple list
replacement ;') What's the simplest way to go through a list, find
something, and replace it with something else?
vowels
On Sat, Apr 27, 2013 at 8:31 PM, Jim Mooney wrote:
> On 27 April 2013 02:55, Amit Saha wrote:
>> On Sat, Apr 27, 2013 at 7:49 PM, Jim Mooney wrote:
>>> Why isn't 'e' changing to 'pP here when the vowel list is mutable:
>>>
>>> vowelList = list('aeiouy')
>>>
>>> for x in vowelList:
>>> if x =
On 27 April 2013 02:55, Amit Saha wrote:
> On Sat, Apr 27, 2013 at 7:49 PM, Jim Mooney wrote:
>> 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'
>
> This is because x is really a l
On Sat, Apr 27, 2013 at 7:49 PM, Jim Mooney wrote:
> 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'
This is because x is really a label for the item in your list. It does
not represent
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
___
Tutor maillist - Tutor@pyt