Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:07:29+00:00 2026-06-14T18:07:29+00:00

Hi my question relates to a post a long time ago by some user

  • 0

Hi my question relates to a post a long time ago by some user here:

Find and replace string values in Python list

For my specific situation. I have a list like this:

appl =  ['1', 'a', 'a', '2', 'a']

I want to replace only the “a single unknown” instance of “a” with just an empty space(that holds the position of where “a” used to be). I am unsure of how to do it for only one character. Can anyone help? Thanks in advance.

EDIT: i Should mention that I need to use an “index” function to first locate the “a” since it is a changing variable. And then I need code that will replace the character.

EDIT2: A lot of people are assuming the index will be 2, but I want to point out that the index of the character is not known. Also “a” will be present in the list approximately ~20 times(will remain a fixed number) but their locations will be changing. I want to replace an “a” based on user input. This is the actual list I am working with:

track  [2] =   ["|","@","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"]

@ is a charachter, | is a border and ” ” is an empty space.
A user enters input to choose how much @ moves to the right and a new image is displayed that shows the new location of @ and the old location of @ is replaced with a space. The length of the list remains constant. This is the context of my question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:07:30+00:00Added an answer on June 14, 2026 at 6:07 pm

    You may use index to achieve this goal, along with a loop.
    Here is a little function for it:

    def replace_element(li, ch, num, repl):
        last_found = 0
        for _ in range(num):
            last_found = li.index(ch, last_found+1)
        li[li.index(ch, last_found)] = repl
    

    use:

    replace_element(appl, 'a', 2, ' ')
    

    This method is particularly nice because it throws the following error when the charactor is not in the list:

    ValueError: 'a' is not in list
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first post here! My question relates to iframes and php mostly So... it's
I can't find what causing this error in my database, I posted some question
I have been having a look to some post here related to the post
while writing the question subject I came across some other allmost related post ...leading
This post relates to a previous that i posted but the question is different
Sorry for the two fold question in one post. This indirectly relates to a
This question relates to my other post . Ok so after a bit more
This is a follow-up question related to my previous post . Below is a
This question is related to my previous post Image Processing Algorithm in Matlab in
This question is related to this SO post Rather than using a recursive CTE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.