Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying Lists
#11
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)
Reply
#12
(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
Reply
#13
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Modifying code cheburashka 1 1,254 Dec-13-2021, 01:01 PM
Last Post: Kebap
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,312 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,190 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020