Re:The Non-Programming Programmer
by jbellis on Monday February 22, 2010 @08:57AM
(#1142617)
I love interview questions that make Python look awesome.
[ Parent
| on HN ]
python -c "print '\n'.join(open('file.txt').readlines()[::-1])"
Hmmm, slightly longer then the Perl version ;-) python -c "print '\n'.join(reversed(list(open('test.py'))))"
Somewhat more elegant, but still lots of parentheses.
Re:The Non-Programming Programmer
by RiderOfGiraffes on Monday February 22, 2010 @02:36PM
(#1143506)
It's also wrong - "readlines" keeps the "\n", and you've added another one between lines.
Indeed. A cosmetic refinement, but it should really be:
python -c "print ''.join(reversed(list(open('test.py'))))"
That's even two characters less!