3 ms·
Just FYI, you can clean this up a teeny bit by removing the square brackets to make it a generator expression. Not a big deal but someone might be enlightened.
by lacker 18y ago
Just FYI, you can clean this up a teeny bit by removing the square brackets to make it a generator expression. Not a big deal but someone might be enlightened.
sum(random.randint(1, 6) for _ in range(3))
- thomaspaine 18y agoDoh! You're right. And I just read an article yesterday comparing the speed of generators with list comprehensions http://ikanobori.jp/weblog/2009/04/08/python-sum-of-file-generators-vs-list-comprehensions/ http://ikanobori.jp/weblog/2009/04/08/python-sum-of-file-gen...