KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Python, is there any difference between creating a generator object through a generator expression versus using the yield statement? Using yield : def Generator(x, y): for i in xrange(x): for j in xrange(y): yield(i, j) Using generator expression : def Generator(x, y): return ((i, j) for i in xrange(x) for j in xrange(y)) Both functions return generator objects, which produce tuples, e.g. (0,0), (0,1) etc. Any advantages of one or the other? Thoughts?
Tags (comma-separated)
Save Edits
Cancel