Python Forum
How to append at a specific position
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append at a specific position
#3
(Sep-21-2019, 12:57 AM)ichabod801 Wrote: I would use enumerate and then index assignment.

Do you mean doing it this way? It did work if each letter is unique, however when there are two same letters within line 1 it will only detect and replace the first one and igonring the second one.
line1 = 'november'
line2 = ['*', '*', '*', '*', '*', '*', '*', '*',]
password = input('enter a letter in the password')

for i in line1:
    if i == password:
        line2[line1.index(i)] = password
        print(line2)
result of running this code:
['*', '*', '*', 'e', '*', '*', '*', '*']
Reply


Messages In This Thread
How to append at a specific position - by Carson147 - Sep-21-2019, 12:09 AM
RE: How to append at a specific position - by Carson147 - Sep-21-2019, 01:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to append a value to specific excel cell using openpyxl hobbyist 0 4,901 Mar-05-2021, 07:14 PM
Last Post: hobbyist
  Printing string at specific position on terminal - not showing __Mathieu__ 1 2,421 Sep-07-2020, 10:32 AM
Last Post: Larz60+
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,642 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  Delete specific lines contain specific words mannyi 2 4,187 Nov-04-2019, 04:50 PM
Last Post: mannyi
  [split] How to write at a very specific position of a text file Lalit 1 4,062 Feb-01-2018, 04:44 PM
Last Post: dalwood

Forum Jump:

User Panel Messages

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