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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:50:56+00:00 2026-05-28T00:50:56+00:00

I have to print several rows of data and do it good. I can

  • 0

I have to print several rows of data and do it good. I can do it with C++ changing parameters of std::cout, but I can’t understand how I can do it with Python. For example, I have this:

row1 = [1, 'arc1.tgz', 'First', '15.02.1992']
row2 = [16, 'arc2modified.tgz', 'Second', 'today']
row3 = ['112', 'arc89.tgz', 'Corrupted', 'unknown']

I want to print text like this:

1    arc1.tgz          First      15.02.1992
16   arc2modified.tgz  Second     today
112  arc89.tgz         Corrupted  unknown

It seems that it would be a clever idea to put it in one list and then count symbols in each string and then add spaces, but I’d like to know if there is more clever way to do it.

The main problem is that I can use only default Python’s modules. Is there any possibility to do it? Thanks a lot!

  • 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-28T00:50:57+00:00Added an answer on May 28, 2026 at 12:50 am
    my_matrix = [row1, row2, row3]
    print "\n".join(["\t".join(map(str, r)) for r in my_matrix])
    

    ETA: My original answer missed that you wanted each column to be of a fixed width, using padded spaces (rather than tabs). It also looks like you want exactly two spaces between the longest datum and the next column. In that case, it can be done as follows (note that string is a built-in, default Python module):

    import string
    
    max_lens = [max([len(str(r[i])) for r in my_matrix])
                    for i in range(len(my_matrix[0]))]
    
    print "\n".join(["".join([string.ljust(str(e), l + 2)
                    for e, l in zip(r, max_lens)]) for r in my_matrix])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset called results with several rows of data. I'd like to
There have been several questions posted to SO about floating-point representation. For example, the
I have several objects in my app that can become nil at some point
if for example i have : #define PRINT(x) fprintf(stderr, x); and in code i
The Situation I have a WPF program that I want to print several documents
I have a table with ~100,000 rows. I am trying to print to screen
Is there a way to have pointers to rows in a database? for example
I have print $str; abcd*%1234$sdfsd..#d The string would always have only one continuous stretch
I have a situation where I have to print out a NUL character if
I'm trying to have Joda print 0 seconds if the input time is zero,

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.