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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:01:38+00:00 2026-06-11T22:01:38+00:00

In a comparison function I am bascially looking for a pattern (e.g. AAA) inside

  • 0

In a comparison function I am bascially looking for a pattern (e.g. “AAA”) inside a long binary object (for an example, aaaAAAbbbBBB)

I’m working backwards through the file (I know the match will be closer to the end than beginning), an adding 1 byte to the variable that is being checked for the match:

1. aaaAAAbbbBB[B]
2. aaaAAAbbbB[BB]
3. aaaAAAbbb[BBB]
4. aaaAAAbb[bBBB]
5. ... 
n. aaa[AAAbbbBBB] 

match found, offset = -n

Given that I know my pattern is 3 elements long, I wondered if I can simply window the search variable rather than incrementing it – it gets very slow when the match is +1,000,000 elements deep in the list – windowed view of the same data would be:

1. aaaAAAbbb[BBB]
2. aaaAAAbb[bBB]B
3. aaaAAAb[bbB]BB
4. aaaAAA[bbb]BBB
5. ...
n. aaa[AAA]bbbBBB

match found, offset = -n

My current search looks like:

if marker in f_data[-counter:]:
    offset = (len(f_data)-counter)+len(marker)
    return offset

In MATLAB I would have used the array addressing to move through the array,(e.g. calling window = a[5:8], window = a[4:7] etc) but I don’t think that’s possible in Python (2.7)

I can see a few suggestions for using a sliding window, ( Rolling or sliding window iterator in Python – this looks like a close match) but I can’t see how to implement it or they reference libs that I don’t know how to use.

Is there a built in function for doing this?

  • 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-11T22:01:39+00:00Added an answer on June 11, 2026 at 10:01 pm

    Why not just use rfind() or rindex()?

    haystack = "aaaAAAbbbBBB"
    needle   = "AAA"
    
    pos = haystack.rfind(needle)
    
    if pos >= 0:
        print "found at", pos - len(haystack)
    else:
        print "not found"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a comparison website, so needless to say the search function is
I am looking for some SQL varchar comparison function like C# string.compare (we can
Lets take qsort()'s comparison callback function as an example int (*compar)(const void *, const
I wrote my comparison function int cmp(const int * a,const int * b) {
Is there any way to override the comparison function in a F# set? I
I want to pass an array of arbitrary struct pointers and a comparison function
I know how function comparison works in Python 3 (just comparing address in memory),
There is a following function that is supposed to make a comparison between 2
I'm trying to write a merge-sort function that takes a list and a comparison
In .NET, the Generics Lists have a sort function that accepts IComparer or Comparison

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.