Credit: Adapted from Free Code Camp
Challenge
We have a list of dictionaries representing different people in our contacts list.
Complete the look_up_profile() function that takes name and a field as arguments included below
The function should check if name is an actual contact's firstName and the given field exists in that contact dictionary.
If both are true, then return the "value" of that field.
If name does not correspond to any contacts then return "No such contact"
If the field does not correspond to any valid properties of a contact found to match name then return "No such property"
starter code
contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
}
];
def look_up_profile(name, field):
pass # fill in your solution here
// Change these values to test your function
look_up_profile("Akira", "likes")
Credit: Adapted from Free Code Camp
Challenge
We have a list of dictionaries representing different people in our
contactslist.Complete the
look_up_profile()function that takesnameand afieldas arguments included belowThe function should check if
nameis an actual contact's firstName and the givenfieldexists in that contact dictionary.If both are true, then return the "value" of that
field.If
namedoes not correspond to any contacts then return "No such contact"If the
fielddoes not correspond to any valid properties of a contact found to match name then return "No such property"starter code