forked from HasBob/IntroPython2015
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiPython_session09.txt
More file actions
117 lines (117 loc) · 2.13 KB
/
Copy pathiPython_session09.txt
File metadata and controls
117 lines (117 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
1: from iterator_2 import IterateMe_2
2: my_iter = IterateMe_2(2, 10, 2)
3:
for i in my_iter:
print(i)
4:
for i in my_iter:
print(i)
5: my_iter[2]
6
6: from iterator_1 import IterateMe_1
7: test_me = IterateMe_1(3, 9, 3)
8:
for i in test_me:
print(i)
9:
for i in test_me:
print(i)
10: test_me[1]
11: test_me = IterateMe_1(3, 9, 3)
12: test_me[1]
3
13:
for i in test_me:
print(i)
14: test_me[1]
15:
def recyclables():
yield 'cans'
yield 'bottles'
yield 'paper'
16:
for i in recyclables():
print(i)
17: recyclables()
<generator object recyclables at 0x1110c1a40>
18: test = recyclables()
19: next(test)
'cans'
20: next(test)
'bottles'
21: next(test)
'paper'
22: next(test)
23: test2 = recylables()
24: test2 = recyclables()
25: next(test2)
'cans'
26: test3 = recylclables()
27: test3 = recyclables()
28: next(test3)
'cans'
29: next(test2)
'bottles'
30:
def counter():
print('counter: starting counter')
i = -3
while i < 3:
i = i + 1
print('counter: yield', i)
yield i
return None
31:
def counter():
print('counter: starting counter')
i = -3
while i < 3:
i = i + 1
print('counter: yield', i)
yield i
return None
32:
def counter():
print('counter: starting counter')
i = -3
while i < 3:
i += 1
print('counter: yield', i)
yield i
return None
33: counter
<function __main__.counter>
34: test = counter()
35: test
<generator object counter at 0x1110c1d00>
36:
for i in test:
print(i)
37: print(repr(test))
38:
def sum_generator():
i = 0
isum = 0
while True:
yield isum
i += 1
isum += i
39: t = sum_generator()
40:
for i in range(5):
next(t)
41:
for i in range(5):
print(next(t))
42: t = sum_generator()
43:
for i in range(5):
print(next(t))
44:
for i in range(5):
print(next(t))
45:
for i in range(5):
print(next(t))
46: hist -f class_history.py
47: history -n -o -f test_history.txt