I'm trying to make a method that iterates over a list and returns the next element.
That's listDenominations:
[2, 5, 7, 10, 25, 30, 50, 70]
That's the method I'm working on:
class SomeClass
def iterDenominations(self):
it = iter(self.listDenominations)
yield it.__next__()
# much later in the code
C = SomeClass()
When I call the method and print the result
firstCall = C.iterDenominations()
print(firstCall)
secondCall = C.iterDenominations()
print(secondCall)
, the first two prints are:
<generator object Currency.iterDenominations at 0x000001D413F6DC10>
<generator object Currency.iterDenominations at 0x000001D4140E2EB0>
These are not the results I was expecting. I'm looking for the elements to be returned sequentially from listDenominations i.e.
after firstCall: [2]
after secondCall: [5]
after thirdCall (as yet unwritten): [7], etc.