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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:45:24+00:00 2026-06-13T16:45:24+00:00

I was wondering that whether there’s a way to refactor the following codes first_run

  • 0

I was wondering that whether there’s a way to refactor the following codes

 first_run = True
 for i in gen:
        if first_run:
            last_head = i[1]
            last_tail = i[2]
            last_chrom = i[0]
            first_run = False
        else:
            func(i[1], last_head)
            func(i[1], last_tail)
            last_head = i[1]
            last_tail = i[2]
            last_chrom = i[0]
  • 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-13T16:45:25+00:00Added an answer on June 13, 2026 at 4:45 pm

    The essential point of your loop seems to be performing some operation on pairs of consecutive elements of the iterable. So I would look to the function pairwise whose definition is given in the itertools module documentation:

    def pairwise(iterable):
        "s -> (s0,s1), (s1,s2), (s2, s3), ..."
        a, b = tee(iterable)
        next(b, None)
        return izip(a, b)
    

    Note that this is not an actual itertools function, you will have to copy and paste the implementation into your code. Anyway, with this function, your loop can be implemented like so:

    for a, b in pairwise(gen):
        func(b[1], a[1])
        func(b[1], a[2])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been wondering whether there is any code out there that enables representing
I'm wondering whether there's an existing framework or technology concept for the following project.
I'm wondering whether there is an existing Java class that, given a Java bean,
I am just wondering whether there is a good login window open source that
I am wondering whether there is a way to resize a chart using Apache
I was wondering whether there're recommendable sites, that host collections of good and useful
I am wondering if the following is a known issue and whether there is
I was wondering, whether there is a way to preprocess freemarker template with some
I am wondering whether there are libraries in .NET that make it easy to
I am wondering whether there is any way to achieve partial JSP rendering in

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.