Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using python write the code.., for each pic.. Accessing a Dictionary Dictionarie

ID: 3708398 • Letter: U

Question

using python write the code.., for each pic..

Accessing a Dictionary Dictionaries are iterable objects that store associations between 'keys' and values Here is a dictionary that accociates weekday names with a 'day number. f'Sunday':0, 'Monday' :1, 'Tuesday' :2, 'Wednesday':3, Thursday':4, 'Friday' :5, 'Saturday' :6) Values can be retrieved from dictionaries using square brackets, in the same way that elements of a string or a list can be selected. The difference here is that the key goes within the square brackets. Write a function get value(dictionary, key) which returns the value for the given key in the given dictionary

Explanation / Answer

def get_value(dictionary, key):
    try:
      return dictionary[key]
    except:
      return -1

def get_value(dictionary, key):
    if dictionary.get(key) != None:
       return dictionary.get(key)
    else:
       return -1;

def big_keys(dictionary, val):
    list = []
    for k in dictionary:
        if dictionary[k] > val:
           list.append(k)
    return list
def add_to_dict(d, key_value_pairs):
    list = []
    for i in key_value_pairs:
        key = key_value_pairs[i][0]
        val = key_value_pairs[i][1]
        if get_value(d,key) != -1:
           if get_value(d,key) != val:
              list.append(key_value_pairs[i])
              d[key] = val
    return list