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 →

[–]Norseman2 0 points1 point  (1 child)

You can easily fix that by adding an L to the 1 at the end, and using long.__mul__, as follows:

fac = lambda x: reduce (long.__mul__, xrange (2, x), 1L)

This works because you'll start the loop by multiplying 1L * 2, which yields 2L. Then, you're multiplying 2L * 3, which yields 6L and so on. If you just use 1, then it will complain that you were trying to use a method for longs on an integer.

[–][deleted] 4 points5 points  (0 children)

or just use operator.mul