Is there a simple way to detect the last iteration while iterating over a dictionary using iteritems()
?
The iteritems() method generates an iterator object of the DataFrame, allowing us to iterate each column of the DataFrame. ;0. Note: This method is the same as the items() method. Each iteration produces a label object and a column object. The label is the column name.
In order to iterate over the values of the dictionary, you simply need to call values() method that returns a new view containing dictionary's values.
There is an ugly way to do this:
for i, (k, v) in enumerate(your_dict.iteritems()):
if i == len(your_dict)-1:
# do special stuff here
But you should really consider if you need this. I am almost certain that there is another way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With