Enormous Input and Output Test

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat Oct 10 07:51:18 EDT 2009


John Yeung wrote:
> P.S.  I hope people realize that the concise, intuitive, readable
> answers we all tried in our first couple of (failed) attempts are much
> more Pythonic than the beasts that were created just for SPOJ.

Well, it is not often that we need to micro optimize stuff (or how would you call it) in 
Python, but this was a fun exercise to do that. You need to think about the small tricks 
that you can use to speed up your code. And then you come up with things like:

- avoid method/function calls
- use table lookups instead of computation
- use iterators
- use tools like psyco to help you out in the odd case where the above doesn't cut it

These things are useful to keep in mind also in general I think!

-irmen


PS the actual loop of my solution isn't that much bigger than it was in my first, most 
readable, attempt. But I think that has everything to do with the complexity of the 
task: it is very simple. Ofcourse I cannot speak about the implementation of the 
solutions that are still faster by a factor of 2...



More information about the Python-list mailing list