I was playing with Generators and found that using Generators time is bit more 
than list-comprehensions or I am doing it wrong?


Function with List comprehensions:

def sum_text(number_range):
    return sum([i*i for i in xrange(number_range)])

%timeit sum_text(100000000)
1 loops, best of 3: 14.8 s per loop

Using generator Expressions:

def sum_text(number_range):

    return sum((i*i for i in xrange(number_range))) 

%timeit sum_text(100000000)

1 loops, best of 3: 16.4 s per loop


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to