title: interpolation of data in dictionary python 3
body: <p>I have a python program which performs calculations using nested dictionaries. The problem is, if someone enters a value not in one of the dictionaries it won't work. I can either force the user to choose from the values but I'd rather perform interpolation to get the 'expected' value. I cannot figure out how to unpack these dictionaries, get them ordered, and perform the interpolation though.</p>
  
  <p>Any help would be greatly appreciated. My code is below.</p>
  
  <p>Dictionaries like this:</p>
  
  <pre><code>from decimal import *
  pga_values = {
      "tee": {
          100:2.92, 120:2.99, 140:2.97, 160:2.99, 180:3.05, 200:3.12,       240:3.25, 260:3.45, 280:3.65,
      300:3.71, 320:3.79, 340:3.86, 360:3.92, 380:3.96, 400:3.99, 420:4.02, 440:4.08, 460:4.17,
      480:4.28, 500:4.41, 520:4.54, 540:4.65, 560:4.74, 580:4.79, 600:4.82
  },
  "fairway": {
      5:2.10,10:2.18,20:2.40,30:2.52,40:2.60,50:2.66,60:2.70,70:2.72,80:2.75,
  </code></pre>
  
  <p>ETC... (edited to be concise)</p>
  
  <pre><code>lie_types = set(pga_values.keys())
  user_preshot_lie = input("What was your pre-shot lie type?")
  user_preshot_distance_to_hole = Decimal(input('How far away from the hole   were you before your shot?'))
  user_postshot_lie = input("What was your post-shot lie type?")
  user_postshot_distance_to_hole = Decimal(input('How far away from the hole were you?'))
  assert user_preshot_lie in lie_types
  assert user_postshot_lie in lie_types
  
  preshot_pga_tour_shots_to_hole_out = pga_values[user_preshot_lie][user_preshot_distance_to_hole]
  postshot_pga_tour_shots_to_hole_out = pga_values[user_postshot_lie][user_postshot_distance_to_hole]
  
  user_strokes_gained = Decimal((preshot_pga_tour_shots_to_hole_out -     postshot_pga_tour_shots_to_hole_out)-1)
  
  print(user_strokes_gained)
  </code></pre>