-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItterator
52 lines (42 loc) · 1.07 KB
/
Itterator
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
# Classic itterator
def itterator(n=3) :
count = 0
while count < n :
count += 1
yield count
# Complexe itterator
def complexItterator() :
count = 0
while True :
count += 1
yield count
# Recreation de l'itteration
class Mon_itterator (object) :
def __init__(self, n) :
self.num = 0
self.n = n
def __iter__(self) :
return self
def __next__(self) :
return self.next()
def next(self) :
if self.num < self.n :
self.num += 1
return self.num
else : raise StopIteration()
# Recreation de l'itteration complexe
class Mon_itterator_complexe (object) :
def __init__(self) :
self.num = 0
def __iter__(self) :
return self
def __next__(self) :
return self.next()
def next(self) :
print(self.num)
if self.num % 2 == 0 :
print(self.num)
self.num += 1
return self.num
# Test des itteration
if __name__ == "__main__" : print("Test en cours")