You are viewing a single comment's thread. Return to all comments →
IMO, comprehensions/generators are more readable:
print(sum(abs(ord(s[x]) - ord(s[len(s) - x - 1])) for x in range(len(s)//2)))
And, though speed isn't usually important, for fun:
s = list(map(ord, s)) print(sum(map(abs, (s[x] - s[-x - 1] for x in range(len(s)//2)))))
This would be even faster due to reducing function calls and eliminating global namespace searches in the innermost loop.
Seems like cookies are disabled on this browser, please enable them to open this website
The Love-Letter Mystery
You are viewing a single comment's thread. Return to all comments →
IMO, comprehensions/generators are more readable:
And, though speed isn't usually important, for fun:
This would be even faster due to reducing function calls and eliminating global namespace searches in the innermost loop.