Python Forum

Full Version: Modifying Lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
You should think a little bit yourself:

AlphaNum = "abcdefg0123456p"
currentIndex = 2
replaceList = ['a', 'b', 'c', 'd', 'e']

for i in range(0, currentIndex):
    replaceList[i] = AlphaNum[0]

for x in replaceList:
    print(x)
(Nov-22-2017, 03:55 AM)heiner55 Wrote: [ -> ]You should think a little bit yourself:

Not even incrementing i works:

AlphaNum = "abcdefg0123456p"
currentIndex = 2
replaceList = ['a', 'b', 'c', 'd', 'e']

for i in range(0, currentIndex-1):
    replaceList[i] = AlphaNum[0]
    i += 1    

for x in replaceList:
    print(x)
The second for loop still gives me the same unwanted output:
a
b
c
d
e
It seems you have the wrong sample.
In my last response I removed "-1" in line 5.

AlphaNum = "abcdefg0123456p"
currentIndex = 2
replaceList = ['a', 'b', 'c', 'd', 'e']

for i in range(0, currentIndex):
    replaceList[i] = AlphaNum[0]

for x in replaceList:
    print(x)
Output:
a a c d e
Pages: 1 2