On Sun, Nov 7, 2010 at 16:41, Wayne Werner <waynejwer...@gmail.com> wrote: > On Sun, Nov 7, 2010 at 6:31 PM, Hugo Arts <hugo.yo...@gmail.com> wrote: >> >> <snip> >> here's a list comprehension >> >>> a = [x*2 for x in range(10)] >> >>> a >> [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] >> >> here's the equivalent generator expression: >> >>> a = (x*2 for x in range(10)) >> >> <snip> > > Since you're talking about generators and efficiency, it's probably a good > idea to point out that range is only a generator in python 3.x. In python > 2.x it creates a list.
I should have mentioned that I'm using 3.1 . So this version of my function uses a generator, range(), no? def proper_divisors(n): sum_ = 0 for x in range(1,n): if n % x == 0: sum_ += x return sum_ Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor