d = {'apple': 2, 'banana': 3, 'almond':2 , 'beetroot': 3, 'peach': 4} [v[0] for v in sorted(d.items(), key=lambda kv: (-kv[1], kv[0]))]