perl to python
Carl Banks
imbosol at aerojockey.invalid
Tue May 11 23:01:11 EDT 2004
Kirk Job-Sluder wrote:
> Write me a two-line script in python that reads a character delimited
> file, and printf pretty-prints all of the records in a different order.
How about one line (broken into three for clarity):
for line in __import__('sys').stdin:
print ''.join([ x.rjust(10) for x in map(
line.strip().split(',').__getitem__,[4,3,2,1,0]) ])
Believe it or not, I actually do stuff like this on the command line
once in awhile; to me, it's less effort to type this in than to
remember (read: look up) the details of awk syntax. I don't think I'm
typical in this regard, though.
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
More information about the Python-list
mailing list