If it's clear that the values of a dictionary will be used then use the '.items()' method. Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx> Tested-by: Stefan Raspl <raspl@xxxxxxxxxxxxxxxxxx> --- tools/kvm/kvm_stat/kvm_stat | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat index 2b7e83a5f7b8..c15950a6c4a4 100755 --- a/tools/kvm/kvm_stat/kvm_stat +++ b/tools/kvm/kvm_stat/kvm_stat @@ -1084,9 +1084,10 @@ class Tui(object): self.screen.clrtobot() stats = self.stats.get(self._display_guests) total = 0. - for key in stats.keys(): + for key, values in stats.items(): if key.find('(') is -1: - total += stats[key].value + total += values.value + if self._sorting == SORT_DEFAULT: def sortkey((_k, v)): # sort by (delta value, overall value) @@ -1376,8 +1377,7 @@ def batch(stats): s = stats.get() time.sleep(1) s = stats.get() - for key in sorted(s.keys()): - values = s[key] + for key, values in sorted(s.items()): print('%-42s%10d%10d' % (key, values.value, values.delta)) except KeyboardInterrupt: pass @@ -1385,17 +1385,16 @@ def batch(stats): def log(stats): """Prints statistics as reiterating key block, multiple value blocks.""" - keys = sorted(stats.get().keys()) + sorted_stats = sorted(stats.get().items()) def banner(): - for k in keys: - print(k, end=' ') + for key, _ in sorted_stats: + print(key, end=' ') print() def statline(): - s = stats.get() - for k in keys: - print(' %9d' % s[k].delta, end=' ') + for _, values in sorted_stats: + print(' %9d' % values.delta, end=' ') print() line = 0 banner_repeat = 20 -- 2.13.4