I\'m trying to solve this problem from Timus Online Judge. To solve this problem you need generate a sequence of 1 000 000 lowercase Latin letters and write it to stdin in
execution time 0.51s
from sys import stdout
from string import ascii_lowercase
l = 1000000
q = ['a']*l
lc = list(ascii_lowercase)
c = 0
for i in range(0,l-2,3):
j = i // 3
j_26 = j // 26
q[i]= lc[j_26 // 26 % 26]
q[i+1] = lc[j_26 % 26]
q[i+2] = lc[j % 26]
stdout.write(''.join(q))
Try turning some part of it into C++ or another compiled language. That will almost guaranteed make it faster. Python, unfortunately, isn't too fast, especially when it comes to things like this. Try C++, C, or Pascal.
EDIT: Also see the Python Performance Tips