I need to return two values at a time, so I have:
class IterableObject(object):
def __iter__(self):
for item in self.__dict__:
return self.__dict__[item + 1], self.__dict__[item]
So I can have:
myObj1, myObj2 = IterableObject()
value = myObj1.balance - myObj2.balance
Of course it did not work. What am I doing wrong? I think I can not add value on item like that.
In the itertools documentation there is an example function called
pairwisethat you can copy into your project:Use it like:
Note that when you iterate over a
dictthe items are not necessarily returned in order, so you should sort first.