-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_5.py
More file actions
40 lines (34 loc) · 1.14 KB
/
task_5.py
File metadata and controls
40 lines (34 loc) · 1.14 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
import os
import csv
class Iterator1:
def __init__(self, rating: str) -> None:
self.file_names = os.listdir(os.path.join('dataset', rating))
self.limit = len(self.file_names)
self.counter = 0
self.rating = rating
def __next__(self) -> str:
if self.counter < self.limit:
self.counter += 1
return os.path.join(self.rating, self.file_names[self.counter-1])
else:
raise StopIteration
class Iterator2:
def __init__(self, rating: str) -> None:
if (5<int(rating) or int(rating)<1):
raise KeyError
self.file_names = []
for name in os.listdir('dataset_copy'):
if rating == name[0]:
self.file_names.append(name)
self.limit = len(self.file_names)
self.counter = 0
self.rating = rating
def __next__(self) -> str:
if self.counter < self.limit:
self.counter += 1
return os.path.join(self.file_names[self.counter-1])
else:
raise StopIteration
a = Iterator1('1')
for i in range(10):
print(next(a))