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ä
  • 50,538
  • 7
  • 126
  • 127
Afke
  • 899
  • 2
  • 10
  • 21

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,543
  • 1
  • 17
  • 29
-2

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

Vlade
  • 89
  • 1
  • 7