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

Implements my solution #156

Closed
wants to merge 2 commits into from
Closed
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
67 changes: 67 additions & 0 deletions python/beginner/profile_lookup_vinimlo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import json

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"]
}
];

data = json.loads(json.dumps(contacts))

def look_up_profile(name, field):

boolName = False
boolField = False

for item in data:
for title, value in item.items():
if title == "firstName":
firstName = value
if name == firstName:
boolName = True
boolField, fieldValue = getsField(item, field)

if boolName:
if boolField:
return print(fieldValue)
else:
return print("No such property")
else:
return print("No such contact")

pass

def getsField(item, field):

boolField = False
fieldValue = None

for title, value in item.items():
if title == field:
boolField = True
fieldValue = value

return boolField, fieldValue

look_up_profile("Akira", "like")