change line with columns when print

sandric ionut sandricionut at yahoo.com
Wed Oct 1 14:39:49 CEST 2008


Even better,

Thank you all

Ionut



----- Original Message ----
From: D'Arcy J.M. Cain <darcy at druid.net>
To: sandric ionut <sandricionut at yahoo.com>
Cc: python-list at python.org
Sent: Wednesday, October 1, 2008 3:13:55 PM
Subject: Re: change line with columns when print

On Wed, 1 Oct 2008 04:43:34 -0700 (PDT)
sandric ionut <sandricionut at yahoo.com> wrote:
> 
> 
> Hello:
> I have a text file that looks like:
> 0 23
> 1 342
> 3 31
> and I want to read the file and print it out like:
> 0 1 3
> 23 342 31
> 
> How can I do this?

Probably tons of ways.  Here's one with no input checking.

L = [x.strip().split() for x in open("infile") if x]
for i in range(2):
  print ' '.join([x[i] for x in L])

-- 
D'Arcy J.M. Cain <darcy at druid.net>        |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212    (DoD#0082)    (eNTP)  |  what's for dinner.



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081001/aad828bd/attachment.html>


More information about the Python-list mailing list