#!/usr/bin/env python3 # -*- coding: utf-8 -*- my_dict = {'200': 'backup01.hw', '213': 'rgw.n2.hw', '244': 'ceph01.n2.hw', '245': 'ceph02.n2.hw', '246': 'ceph03.n2.hw', '247': 'ceph04.n2.hw', '52': 'balance02.int.hw', '77': 'test.traffic.test'} for key, val in sorted(my_dict.items(), key=lambda x: int(x[0])): print(key + '\t\tPTR\t' + val + ".")