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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:22:31+00:00 2026-06-14T05:22:31+00:00

I have to write a program that finds all of the index values for

  • 0

I have to write a program that finds all of the index values for specific element in list or a string. I have to use recursion, and my function can only take two arguments.

My problem is that my program finds only the first index and then stop. How can I change it to meet my requirements?

My code:

def find_all(L, v):
    return 0 if L[0] == v else 1 + find_all(L[1:], v)

Input:

  1. find_all( [1,2,3,4,2,4,5,2,1], 2)
  2. find_all("hello wonderful world", "w")

Desired output:

  1. [1,4,7]
  2. [6,16]
  • 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-14T05:22:33+00:00Added an answer on June 14, 2026 at 5:22 am

    You can use Pythons ability to walk backwards through a list and grab the last element. Then put lists together with the + operator. By going through the list backwards you’re able to find the indice when a value is found, rather than losing it when you move from the start of the list to the end.

    def find_all(L, v):
        if not L:
                return []
    
        result = []
        if L[-1] == v:
                result = [len(L)-1]
    
        return find_all(L[:-1], v) + result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a program that finds square root of an integer that
I have to write a program that sniffs network packets (part1-the simple part). And
I have to write a Java program that tells what coins to give out
I have to write a daemon program that constantly runs in the background and
I wanted to write a program that test if two files are duplicates (have
I have been assigned wit the task to write a program that takes a
I have a program that looks like this. I need to consistently write something
I have a robot that I need to write an autonomous program for. The
Background: I have a function in my program that takes a set of points
I've been tasked with a problem that finds all the subsequences for a string.

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.