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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:32:12+00:00 2026-05-27T12:32:12+00:00

I am writing a program to reformat a text file. The old file contains

  • 0

I am writing a program to reformat a text file. The old file contains a couple columns of text like below.

Take
3
29
1001 83.489601 279.859650 1.000000
1002 83.489594 271.848480 0.997735
1003 83.489594 263.837311 0.997337
1004 83.489594 256.076111 0.996816
1005 83.364594 248.189941 0.995626
1006 83.364594 240.178787 0.994840   

My program currently writes this to a new file in a format that I want, and adds some lines. It then looks like this:

clip
Values 12
trick, pos, ypos, similarity
1001 83.489601 279.859650 1.000000
1002 83.489594 271.848480 0.997735
1003 83.489594 263.837311 0.997337
1004 83.489594 256.076111 0.996816
1005 83.364594 248.189941 0.995626
1006 83.364594 240.178787 0.994840

What I need to do now is reverse the vertical order of the third column of numbers for the new file. It should end up looking like this:

clip
Values 12
trick, pos, ypos, similarity
1001 83.489601 240.178787 1.000000
1002 83.489594 248.189941 0.997735
1003 83.489594 256.076111 0.997337
1004 83.489594 263.837311 0.996816
1005 83.364594 271.848480 0.995626
1006 83.364594 279.859650 0.994840

I can split out the third set of numbers one line at a time but can’t figure out how I should go about writing that column back in to it’s correct position. There are multiple blocks of this in the file and they vary in length. I just need a direction to start working in as I am completely lost right now. What kind of functions should I be looking at to help me accomplish this? Any help would be appreciated. I am new to coding and am using Python 3.2.2

  • 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-27T12:32:13+00:00Added an answer on May 27, 2026 at 12:32 pm

    The steps are:

    • Read in each line, splitting it into fields
    • Accumulate the results in a list of lists
    • Use zip(*t) to transpose the array
    • Pick the appropriate row (formerly a column), and use list.reverse
    • Transpose back to column format
    • Write the rows to disk

    Here’s an example:

     >>> s = '''\
     1001 83.489601 279.859650 1.000000
     1002 83.489594 271.848480 0.997735
     1003 83.489594 263.837311 0.997337
     1004 83.489594 256.076111 0.996816
     1005 83.364594 248.189941 0.995626
     1006 83.364594 240.178787 0.994840
     '''.splitlines()
     >>> result = []
     >>> for line in s:
             result.append(line.split())
    
    
     >>> t = zip(*result)
     >>> t[2] = t[2][::-1]
     >>> result = zip(*t)
     >>> for row in result:
             print ' '.join(row)
    
    
     1001 83.489601 240.178787 1.000000
     1002 83.489594 248.189941 0.997735
     1003 83.489594 256.076111 0.997337
     1004 83.489594 263.837311 0.996816
     1005 83.364594 271.848480 0.995626
     1006 83.364594 279.859650 0.994840
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that contains a generational garbage collector. There are just two
I am writing a program that creates an image file. I want the original
I writing a program in Delphi 2010. Part of the program deals with File
I am writing a program which will type a line of text in 5
I have tried writing program that plays a sound file but have been unsuccessful
I am writing a program that gets a HTML file in Android and I
I'm writing a program that needs to watch for file system events on multiple
I am writing a program that takes in an input file from the user.
I am writing a program like unix tr, which can replace string of input.
Im writing a program that should read input via stdin, so I have the

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.