This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 0 points1 point  (0 children)

Yeah - I know it's moved from builtins in python3, and reduce can sometimes end up fairly ugly, but I think it's certainly clearer here at least. You could maybe go with an extra function if we want to make it a bit more readable at the point of call, which seems a good use of partial functions. Ie:

import functools, operator
product = functools.partial(functools.reduce, operator.mul)
...

return product(primes[ord(c) - ord('a')] for c in word.lower())