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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:11:48+00:00 2026-05-31T18:11:48+00:00

I am new to python and I am trying to implement rfind function using

  • 0

I am new to python and I am trying to implement rfind function using find.

def rfind_imp(s,t):
    ss = s
    fpos = 0
    while(True):             
         fpos = s.find(t,fpos)
         ss=ss[fpos:]

         if(ss):    
           fpos = fpos +1    
         else:
           return fpos

print rfind_imp("I saw a donkey,I saw a saw "," ")
print "I saw a donkey,I saw a saw ".rfind(" ")

But the issue I am facing is I am getting 16th charcter as rfind value. Can some one help me find where I am doing a mistake. Also any suggestions for better implementation of rfind using find should be helpful.

  • 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-31T18:11:49+00:00Added an answer on May 31, 2026 at 6:11 pm

    I think your algorithm should be implemented like this:

    def rfind_imp(s, t):
        fpos = -1
        while True:
             pos = s.find(t, fpos + 1)
             if pos == -1:
                return fpos
             fpos = pos
    

    Another algorithm that’s probably faster for strings with many ocurrences of t:
    (Edit: made it work for strings with more than one character)

    def rfind2(s, t):
        pos = s[::-1].find(t[::-1])
        if pos == -1:
            return pos
        return len(s) - pos - len(t)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to python but I've run into a hitch when trying to implement
i am trying to implement RSA in python(i am new to python) for my
I'm trying to implement Window socket using Python. Mostly, everything has been so far
I´m new in python and I´m trying to find the best way to approach
I've been trying to learn Python, and while I'm enthusiastic about using closures in
I am new to python and trying to learn. I am trying to implement
I am somewhat new to RESTful APIs. I'm trying to implement a python system
I'm new Python and trying to implement code in a more Pythonic and efficient
I am trying to implement a simple websoket server on python, using RFC 6455
Im new two python and am trying to grow a dictionary of dictionaries. I

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.