Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beginner Issue #2 Solution #74

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions beginner/profile-lookup_david.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
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"
"""

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: str, field: str) -> str:
for contact in contacts:
first_name = contact.get("firstName")
if first_name and first_name.casefold() == name.casefold():
field_value = contact.get(field)
return field_value if field_value else "No such property"
return "No such contact"



# Change these values to test your function
look_up_profile("Akira", "likes")