0

I have got a dictionary in the form of:

{0.1: (0.7298579,0.7987254)}

which corresponds to: {test_size: (train_error, test_error)}.

I would like to change the key value test_size into 1 - test_size. So that we obtain:

{0.9: (0.7298579, 0.7987254)}

How can I do this?

Ilja Everilä
  • 45,748
  • 6
  • 100
  • 105
Afke
  • 787
  • 1
  • 8
  • 19

2 Answers2

5

You can do this :

>>> d = {0.1:(0.7298579,0.7987254)}
>>> new_d = {1-k: v for k, v in d.items()}
>>> new_d
{0.9: (0.7298579, 0.7987254)}
3kt
  • 2,453
  • 1
  • 16
  • 27
-2

If the dict is not horribly huge, you can just create a new dict and copy the old one with new keys.

Vlade
  • 49
  • 1
  • 6