How can i do this in Python?

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Jan 25 01:47:15 EST 2007


At Thursday 25/1/2007 01:25, NoName wrote:

>perl -ane "print join(qq(\t), at F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"

Must be done on a single line?
I'm not sure if I've got right the behavior - it's been some time 
since I quit writing Perl code. The script iterates over all lines 
contained on all files specified on the command line; for each line, 
splits it on whitespace; then it prints a selected set of fields 
(columns 0, 1, 20, 21...) using a tab character as field separator.

=== cut ===
import operator,fileinput

mapper = map(operator.itemgetter, [0,1,20,21,2,10,12,14,11,4,5,6])
for line in fileinput.input():
     fields = line.split()
     print '\t'.join(m(fields) for m in mapper)
=== cut ===


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list