4 ms·
Why are you optimizing the LOC only for Java? With a little bit of tweaking, Python can do the whole thing in 2 lines -- no imports, libraries or closing braces
by depressedpanda 9y ago
Why are you optimizing the LOC only for Java? With a little bit of tweaking, Python can do the whole thing in 2 lines -- no imports, libraries or closing braces needed:
with open('alice.txt') as inp, open('new_alice.txt', 'w') as out:
out.write('\n'.join([line.rstrip().replace('Alice', 'Dora the Explorer') for line in inp]))
The author's point is that Java is verbose and requires a lot of boilerplate, which has benefits and drawbacks. I think her example does a decent job of illustrating that.