0

This is my dictionary

x = {'balance': 19.1, 'advance': 0.4, 'withdrawal': 53.0, 'deposit': 24.7, 'transfer': 2.8000000000000003}

when i try to sort it by

sorted(x) = ['advance', 'balance', 'deposit', 'transfer', 'withdrawal']

it only gave me the keys, i also need the corresponding values with it

Kutam
  • 11
  • 3

1 Answers1

0
x = {'balance': 19.1, 'advance': 0.4, 'withdrawal': 53.0, 'deposit': 24.7, 'transfer': 2.8000000000000003}
print [i for i in sorted(x.items())]

Output:[('advance', 0.4), ('balance', 19.1), ('deposit', 24.7), ('transfer', 2.8000000000000003), ('withdrawal', 53.0)]

vks
  • 67,027
  • 10
  • 91
  • 124