I have the following code which works. The test_generator function returns a list. But in order to access this list i have to loop twice with 2 for loops as you can see at the bottom. Why i don't get the list item on the first loop for item in test.test_generator(t)
and i need 2 loops . Is there a way to get the list values with just one loop ?
class test:
def __init__(self):
self.counter = 0
def test_generator(self):
record = []
c = 0
self.counter = self.counter + 1
if (self.counter <= 50):
while c < 5:
record.append(self.counter + 1)
c = c + 1
yield record
t = test()
while True:
for item in test.test_generator(t):
for i in item:
print(t.counter)