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 7561969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:17:47+00:00 2026-05-30T13:17:47+00:00

Sorry for the very basic question, but this is actually a 2-part question: Given

  • 0

Sorry for the very basic question, but this is actually a 2-part question:

  1. Given a list, I need to replace the values of ‘?’ with ‘i’ and the ‘x’ with an integer, 10. The list does not always have the same number of elements, so I need a loop that permits me to do this.

    a = ['1', '7', '?', '8', '5', 'x']
    
  2. How do I grab the index of where the value is equal to ‘?’. It’d be nice if this show me how I could grab all the index and values in a list as well.

  • 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-05-30T13:17:49+00:00Added an answer on May 30, 2026 at 1:17 pm

    Write a function for it and use map() to call it on every element:

    def _replaceitem(x):
        if x == '?':
            return 'i'
        elif x == 'x':
           return 10
        else:
            return x
    
    a = map(_replaceitem, a)
    

    Note that this creates a new list. If the list is too big or you don’t want this for some other reason, you can use for i in xrange(len(a)): and then update a[i] if necessary.

    To get (index, value) pairs from a list, use enumerate(a) which returns an iterator yielding such pairs.

    To get the first index where the list contains a given value, use a.index('?').

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is very basic as a question....but I can't my head around
Very sorry for the basic question but I've seen this implemented in so many
I'm sorry for this very newbish question, I'm not much given into web development.
Sorry if this question is very easy, but I can't find the answer anywhere.
I am learning Haskell. I'm sorry for asking a very basic question but I
This is a very basic question, but I'd quite like an explanation of why
I am sorry for the very newbie question, but this is driving me mad.
sorry, this is not a very nice question for here, but I'm very stressed
This is a very basic question - but I haven't been able to find
Sorry for this very basic JQuery question. I created 'mytest' jquery function like this:

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.