Question: python language please Problem 2 (Retrieving Values) Write a second function called getvalue(jsonlist, key) that accepts two arguments: a 2D JSON list in the format
python language please 
Problem 2 (Retrieving Values) Write a second function called getvalue(jsonlist, key) that accepts two arguments: a 2D JSON list in the format returned by the function in Problem 1, and a string/key specifying the key you want to retrieve the value for. This function should iterate through the list to find the matching key and return the corresponding value. If no items within the given list match (i.e., the key does not exist), the function should return an empty string. As an example, if you saved the list from the example in Problem 1 into a variable called mylist, the output of the getvalue function would be: getvalue (mylist, firstname") "dave" getvalue (mylist, "lastname") "mckenney" getvalue (mylist, "position") > "instructor" getvalue (mylist, Wheight") N Problem 3 (Setting Values) Write a function called setvalue(jsonlist, key, newvalue) that accepts three arguments: a 2D JSON list in the format returned by the function in Problem 1, a string/key specifying the key you want to set the value for, and a string/value that should represents the new value for the given key. For example, if you had the same mylist variable from Problem 2 and you executed setvalue(mylist, "position", "president), mylist would then look like I [firstname", "dave"], ['lastname", "mckenney"l, [position", "president'll 2 Problem 4 (List to JSON) Write a function called listtojson(jsonlist) that accepts a 2D list argument in the same format that has been used in the previous problems. The function must return a JSON- formatted string that contains the key/value pairs in the 2D list. For example, if you executed listtojson(mylist) using the modified list from Problem 3, your function should return the following string ('firstname":"dave","lastname"."mckenney" "position presi dent") Problem 5 (Two More Functions) There are two other functions you could try adding to your module. remove(jsonlist, key) - accepts a 2D list and a string/key. This function should find and remove the key/value pair in jsonlist that matches the argument key. If ey is not present, the function does not need to make any changes addsonlist, key, value) - accepts a 2d list, a string/key, and a string/value This function should add the keylvalue pair to the list. Problem 2 (Retrieving Values) Write a second function called getvalue(jsonlist, key) that accepts two arguments: a 2D JSON list in the format returned by the function in Problem 1, and a string/key specifying the key you want to retrieve the value for. This function should iterate through the list to find the matching key and return the corresponding value. If no items within the given list match (i.e., the key does not exist), the function should return an empty string. As an example, if you saved the list from the example in Problem 1 into a variable called mylist, the output of the getvalue function would be: getvalue (mylist, firstname") "dave" getvalue (mylist, "lastname") "mckenney" getvalue (mylist, "position") > "instructor" getvalue (mylist, Wheight") N Problem 3 (Setting Values) Write a function called setvalue(jsonlist, key, newvalue) that accepts three arguments: a 2D JSON list in the format returned by the function in Problem 1, a string/key specifying the key you want to set the value for, and a string/value that should represents the new value for the given key. For example, if you had the same mylist variable from Problem 2 and you executed setvalue(mylist, "position", "president), mylist would then look like I [firstname", "dave"], ['lastname", "mckenney"l, [position", "president'll 2 Problem 4 (List to JSON) Write a function called listtojson(jsonlist) that accepts a 2D list argument in the same format that has been used in the previous problems. The function must return a JSON- formatted string that contains the key/value pairs in the 2D list. For example, if you executed listtojson(mylist) using the modified list from Problem 3, your function should return the following string ('firstname":"dave","lastname"."mckenney" "position presi dent") Problem 5 (Two More Functions) There are two other functions you could try adding to your module. remove(jsonlist, key) - accepts a 2D list and a string/key. This function should find and remove the key/value pair in jsonlist that matches the argument key. If ey is not present, the function does not need to make any changes addsonlist, key, value) - accepts a 2d list, a string/key, and a string/value This function should add the keylvalue pair to the list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
