4 ms·
> Yep, bash is more readable for small scripts I don't agree with that, in my opinion bash is more coincise while python is far more explicit and thus more und
by tyrion 13y ago
> Yep, bash is more readable for small scripts
I don't agree with that, in my opinion bash is more coincise while python is far more explicit and thus more understandable.
Python is not meant to be written in one line; the script could be rewritten in a readable way like this:
import sys
inp = open(sys.argv[1], 'r')
out = open(sys.argv[2], 'w')
out.writelines(sorted(inp))
- brian_cloutier 13y agoThis is my favorite python implementation in this thread. I daresay it's beautiful. Including whitespace it's still half as long as the "11 line" core of the C++ script. There's an unnecessary 'r'. Combined with the line rhythm established by opening the files in consecutive lines you ensure readers who would have been confused by the 'w' will quickly understand. And the last line reads like programmer English; by which I mean English with a SVO word order. Not intuitive to the average person but quite parsable by anybody who's used a modern imperative language. I can't even nitpick your choice of inp instead of input, the rhythm you setup and the contrast with 'out' means it's quite obvious what you mean. Have an upvote.
- ksrm 13y agoEnglish is usually SVO; I assume you meant OVS?
- deleted 13y ago[deleted]
- hcarvalhoalves 13y agoObligatory functional style: import sys reduce(lambda i, o: o.writelines(sorted(i)), map(lambda args: open(*args), zip(sys.argv[1:], ('r', 'w')))) If Guido didn't despised FP so much maybe we could get a nicer lambda syntax... but here's anyway.
- tyrion 13y agoIn my opinion using reduce, map and zip is not a good idea in this case. What are they needed for? I don't even think your approach is more functional than the examples above. I mean, this one line should be equally functional and .. it's shorter and even more understandable: open(sys.argv[2], 'w').writelines(sorted(open(sys.argv[1])) (Btw you're talking about a nicer lambda syntax but imho your example looks ugly because of all the unneeded stuff you've put into it)