Python 2. Iterator, Generator.
When you create a list, you can read list elements one-by-one - this is called iteration.
>>> test_list = [1,2,3]
>>> for element in test_list:
... print element
...
1
2
3
test_list is iterable object. In other words any object which can be used with "for ... in ..." is iterable. Iterable objects are good until they become too big, because iterable object is fully saved in memory.
Generator objects are also iterable objects but they can be read only once and they don't save values but generate needed values on the fly. So you can use generator only one time, because values are not saved in memory.
Generator objects are also iterable objects but they can be read only once and they don't save values but generate needed values on the fly. So you can use generator only one time, because values are not saved in memory.
No comments:
Post a Comment