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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:20:58+00:00 2026-06-05T09:20:58+00:00

I am giving a text file with the format below: 3 Bham Hoover –

  • 0

I am giving a text file with the format below:

3     Bham    Hoover - Vestiva 
123 234 1 456 876 1 876 745 1
0
4     Bham    Vestiva - Greensprings
235 876 1 647 987 1 098 765 1 234 546 1
0

This goes on for several more lines, but I am trying to convert this format to the following:

Event
Disconnect branch from bus 123 to 234 circuit 1
Disconnect branch from bus 456 to 876 circuit 1
Disconnect branch from bus 876 to 745 circuit 1
end
Event 
Disconnect branch from bus 235 to 876 circuit 1
Disconnect branch from bus 647 to 987 circuit 1
Disconnect branch from bus 098 to 765 circuit 1
Disconnect branch from bus 234 to 546 circuit 1
end
  • 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-05T09:21:00+00:00Added an answer on June 5, 2026 at 9:21 am
    from itertools import islice
    with open('file.txt', 'r') as f:
        # iterate over every 3rd line, starting with the 2nd
        for line in islice(f, 1, None, 3):
            parts = line.split()
            print 'Event'
            # iterate over 3-element chunks
            for x in zip(*(iter(parts),) * 3):
                print 'Disconnect branch from bus %s to %s circuit %s' % x
            print 'end'
    

    Output:

    Event
    Disconnect branch from bus 123 to 234 circuit 1
    Disconnect branch from bus 456 to 876 circuit 1
    Disconnect branch from bus 876 to 745 circuit 1
    end
    Event
    Disconnect branch from bus 235 to 876 circuit 1
    Disconnect branch from bus 647 to 987 circuit 1
    Disconnect branch from bus 098 to 765 circuit 1
    Disconnect branch from bus 234 to 546 circuit 1
    end
    

    Credits to the chunking code go to Iteration over list slices

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading integers from a text file, giving them as input to a
I am reading a text file with this format: grrr,some text,45.4321,54.22134 I just have
For a giving DB, I used CodeSmith to generate a text file that has
I am giving a text view to tweet some string . I am applying
I am having issues with giving id to a text box in the aspx
Why is the following code giving an exception? function SetText(index, text) { try {
i am giving a field to user where he can upload any image file
Is there a simple way to export a WPF DataGrid to a text file
I am counting the number of times every word occurs in a text file.
I tried BCP, but doesn't work. Sql keeps giving me some Help text.. Anyway,

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.