This is a function which produces the sum of primes beneath (not including) a certain number (using a variant on the sieve of Eratosthenes). erastosum = lambda x: sum([i for i in xrange(2, x) if i == 2 or i == 3 or reduce(lambda y,z: y*z, [i%j for j in xrange(2,int(i ** 0.5) + 1)])])Excessive use of lambda? Perhaps. Beautification would be nice, but I'm looking for performance optimizations. Sadly, I'm not sure if there is any further way to optimize the setup I've got right now, so any suggestions (on how to, or what else to do) would be nice.
Excessive use of lambda with variant of Sieve of Eratosthenes?
python;optimization;lambda
As much as I love anonymous functions, they can be a nightmare to debug. Splitting this code up piece wise (into an actual function or otherwise) shouldn't and wouldn't decrease it's performance while improving maintenance and portability for you later on.This class is quite efficient for determining primes. Despite being quite lengthy is more efficient than the more usual approach.