CSE 1010 Lecture Notes - Lecture 17: Iter, Standard Streams, Iterator

34 views3 pages
jadetortoise401 and 55 others unlocked
CSE 1010 Full Course Notes
84
CSE 1010 Full Course Notes
Verified Note
84 documents

Document Summary

Iterators: consider how a for loop works. It means every element in collection, put that element in var and execute body_of_loop one time: repeat until all elements have been used, that collection can be a list, string. Something is iterable if it ahs __iter__ method that returns an iterator: >>> y = [2*x for x in m] Typeerror: "myclass" object is not iterable: an interator class, any class that has two special methods. Iter and next: __iter__ should return self python3 count_by_10s. py. Type help, copyright, credits or license for more information. Iterator is an object that represents a stream of data while a generator is a special kind of iterator. It is created as a function that retains its local state between calls ef gen1(): x = 0 while true: yield x #makes it a generator x += 1: a generator comprehension, use parentheses instead of brackets.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions