Question: family = [ { firstName: Jane, middleName: Doe, age: 40, }, { firstName: John, middleName: Smith, age: 42, }, { firstName: Jonny, middleName: Junior, age:
family = [ { "firstName": "Jane", "middleName": "Doe", "age": 40, }, { "firstName": "John", "middleName": "Smith", "age": 42, }, { "firstName": "Jonny", "middleName": "Junior", "age": 10, } ] middle_names = [] for person in family: middle_names.append(person["middleName"]) print(middle_names) Problem 1:
* Create a variable and assign it the length of the middle names list created in the previous cell. (Hint: You don't have to redefine the list in the new cell as long as you ran the previous cell recently) * Use a `while` loop to count up to the length of the middle names list, and print out the index and value of each item in the list using a format string. (Hint: start your counter at `0` and stop iterating before you reach the length by using a `<` operator)
Problem 2:
* Loop through the list of dictionaries defined in the first cell using another `for` loop. (Hint: Again, you do not need to redefine the list of dictionaries from the previous cell as long as you executed it recently) * Nested inside of that loop, loop through the keys in the current dictionary using another `for` loop and the `enumerate()` instruction. * Nested inside of the nested loop, print out the key and value using a format string. (Hint: You'll need to use the key to get the value out of the dictionary) * Also inside of the nested loop, once the index is greater than or equal to 2, break out of the loop.
This is done using Jupyter Notebook so each problem goes into its own respective "cell." The portion that is in Courier font is the first "cell."
Any help is very appreciated!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
