title: How to filter for values within a nested list in a dictionary based on user input?
body: <p>I have a list of key value (name/age) pairs nested within a dictionary. Each key value pair in the list is associated with an ID in this dictionary. I would like to create a new dictionary (which won't be returned at the end of the function) with the ID, name and age of the key value pairs within the range the user selects. I have tried:</p>
  <pre><code>id_dict3 = {222: ['Sachin', 20.0], 388: ['Misty', 70.0], 444: ['Mark', 40.0]}
  def print_data(id_dict3):
      print(id_dict3)
      toloop = &quot;Yes&quot;
      while toloop == &quot;Yes&quot;:
          print(&quot;Filtering your data by minimum and maximum age.&quot;)
          min_age = int(input(&quot;Enter a minimum age value: &quot;))
          max_age = int(input(&quot;Enter a maximum age value: &quot;))
        
          # using loop to iterate through all keys
          res = dict()
          for key, val in id_dict3.items():
              if int(id_dict3[id][1])  &gt;= min_age and int(id_dict3[id][1]) &lt;= max_age:
                  res[key] = val
          print(str(res))
          toloop = input(&quot;Would you like to do filter the data within another age range? Yes or No: &quot;)
          if toloop == &quot;No&quot;:
              return id_dict3
  </code></pre>
  <p>No matter what the age range, it only applies to the last key value pair. For instance, when min_age is 39 and max_age is 49, it will print the entire list. However, if min_age is 60 and max_age is 75 it prints nothing. I would like it to print out the all the ID,name and ages within the range identified by the user. Any suggestions?</p>