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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:06:20+00:00 2026-05-23T17:06:20+00:00

currently I have a very long sequence in a file and I wish to

  • 0

currently I have a very long sequence in a file and I wish to split this sequence into smaller subsequences, but I would like each subsequence to have an overlap from the previous sequence, and place them into a list. here is an example of what I mean:

(apologies about the cryptic sequence, this is all on 1 line)

file1.txt
abcdefessdfekgheithrfkopeifhghtryrhfbcvdfersdwtiyuyrterdhcbgjherytyekdnfiwytowihfiwoeirehjiwoqpft


list1 = ["abcdefessdfekgheithrfkopeifhght", "fhghtryrhfbcvdfersdwtiyuyrterdhc", "erdhcbgjherytyekdnfiwyt", "nfiwytowihfiwoeirehjiwoqpft"]

I can currently split each sequence into smaller saubsequences without the overlaps using the following code:

def chunks(seq, n):
    division = len(seq) / float (n)
        return [ seq[int(round(division * i)): int(round(division * (i + 1)))] for i in xrange(n) ]

in the above code the n specifies how many subsequences the list will be split into.

I was thinking of just grabbing the ends of each subsequence and just concatenating them to the ends of the elements in the list by hard coding it… but this would be inefficient and hard. is there an easy way to do this?

in reality it would be more about 100 characters that i would require to be overlapped.

Thanks guys

  • 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-23T17:06:20+00:00Added an answer on May 23, 2026 at 5:06 pm
    seq="abcdefessdfekgheithrfkopeifhghtryrhfbcvdfersdwtiyuyrterdhcbgjherytyekdnfiwytowihfiwoeirehjiwoqpft"
    >>> n = 4
    >>> overlap = 5
    >>> division = len(seq)/n
    >>> [seq[i*division:(i+1)*division+overlap] for i in range(n)]
    ['abcdefessdfekgheithrfkopeifhg', 'eifhghtryrhfbcvdfersdwtiyuyrt', 'yuyrterdhcbgjherytyekdnfiwyto', 'iwytowihfiwoeirehjiwoqpft']
    

    it is probably slightly more efficient to do it like this

    >>> [seq[i:i+division+overlap] for i in range(0,n*division,division)]
    ['abcdefessdfekgheithrfkopeifhg', 'eifhghtryrhfbcvdfersdwtiyuyrt', 'yuyrterdhcbgjherytyekdnfiwyto', 'iwytowihfiwoeirehjiwoqpft']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very long loop, and I would like to check the status
I currently have this very long if statement: if (somesTring != null && !.equals(somestring)
Here is what I have currently, I'm doing this: current_account.send(object).search(params[:search]).user_id_equals_any(users).visibility_is_any(visibilities) but thats not very
I am using XCode 4. I have a very long .m file with a
I have to read a txt file with lines formated like this: 1: (G,
I currently have a loop something like this: foreach(var item in theList) { //create
I currently have some VERY long winded code for the menu I use on
I currently have a very simple web application written in Django, and I would
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
Very simple + silly question: Does clojure provide multi maps? I currently have something

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.