Wednesday, 12th August, 2009
Project Euler Problem 29.01
So I was looking at Python 3.x and I noticed something… It has Set comprehensions! Like lists, but it only maintains unique items. So we can do Problem 29 in one line!
print(len({a**b for a in range(2,101) for b in range(2,101)}))
Let me be the first to say (On this blog) That’s AWESOME! Even if it’s only in the ‘not quite production ready yet’ Python 3.x branch, it’s a great addition to the language.
Done! :-D