3 ms·
squares = [x * x for x in range(10)] print(min(squares)) print(max(squares)) this one works and looks good.
by c8g 8y ago
squares = [x * x for x in range(10)]
print(min(squares))
print(max(squares))
this one works and looks good.
- wyldfire 8y agorange(10) doesn't properly demonstrate the material differences between generators and lists. Like posted elsewhere, tee is an appropriate solution that preserves the generator's benefits over a list. It's too bad that the example is so synthetic.
- shmageggy 8y agoOne downside of both solutions is that they both traverse the list twice, which could be expensive when we're talking about real data and not toy problems.