Last active
March 15, 2018 16:01
-
-
Save tscizzle/2c7bd4e4d326f8cef14ce92cec201db8 to your computer and use it in GitHub Desktop.
A fun python exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# Exercise #0 | |
# - Implement findPeople | |
# - findPeople takes 1 arg: a list of dicts of the form {'firstName': '__', 'lastName': '__'} | |
# - An element of DATA "matches" an element of the input list if it matches both firstName and lastName | |
# - findPeople should return a list of the same length as the input, with "matches" corresponding to | |
# each element of the input (for examples, see tests below) | |
# - If no match is found in DATA for some element of the input, the corresponding spot in the output array should be None | |
# - If multiple matches are found in DATA for an element of the input, choose the match with the largest age | |
def EXERCISE_0(): | |
DATA = [ | |
{ 'firstName': 'Jane', 'lastName': 'Jordy', 'age': 75, 'handed': 'left' }, | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink', 'age': 64, 'handed': 'left' }, | |
{ 'firstName': 'Jane', 'lastName': 'Shloosh', 'age': 20, 'handed': 'right' }, | |
{ 'firstName': 'Jordy', 'lastName': 'Jordy', 'age': 32, 'handed': 'right' }, | |
{ 'firstName': 'Jane', 'lastName': 'Mudslide', 'age': 7, 'handed': 'left' }, | |
{ 'firstName': 'Brandell', 'lastName': 'Frobb', 'age': 6, 'handed': 'right' }, | |
{ 'firstName': 'Jane', 'lastName': 'Shloosh', 'age': 18, 'handed': 'left' }, | |
{ 'firstName': 'Brandell', 'lastName': 'Frobb', 'age': 10, 'handed': 'left' }, | |
{ 'firstName': 'Brandell', 'lastName': 'Frobb', 'age': 6, 'handed': 'left' }, | |
] | |
def findPeople(peopleToFind): | |
# YOUR CODE HERE | |
pass | |
# tests | |
input0 = [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink' }, | |
] | |
print('input0', findPeople(input0) == [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink', 'age': 64, 'handed': 'left' }, | |
]) | |
input1 = [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink' }, | |
{ 'firstName': 'Jordy', 'lastName': 'Jordy' }, | |
] | |
print('input1', findPeople(input1) == [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink', 'age': 64, 'handed': 'left' }, | |
{ 'firstName': 'Jordy', 'lastName': 'Jordy', 'age': 32, 'handed': 'right' }, | |
]) | |
input2 = [ | |
{ 'firstName': 'Gunder', 'lastName': 'Blinken' }, | |
] | |
print('input2', findPeople(input2) == [ | |
None, | |
]) | |
input3 = [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink' }, | |
{ 'firstName': 'Gunder', 'lastName': 'Blinken' }, | |
{ 'firstName': 'Jordy', 'lastName': 'Jordy' }, | |
] | |
print('input3', findPeople(input3) == [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink', 'age': 64, 'handed': 'left' }, | |
None, | |
{ 'firstName': 'Jordy', 'lastName': 'Jordy', 'age': 32, 'handed': 'right' }, | |
]) | |
input4 = [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink' }, | |
{ 'firstName': 'Jane', 'lastName': 'Shloosh' }, | |
{ 'firstName': 'Gunder', 'lastName': 'Blinken' }, | |
{ 'firstName': 'Brandell', 'lastName': 'Frobb' }, | |
] | |
print('input4', findPeople(input4) == [ | |
{ 'firstName': 'Anna', 'lastName': 'Tenbrink', 'age': 64, 'handed': 'left' }, | |
{ 'firstName': 'Jane', 'lastName': 'Shloosh', 'age': 20, 'handed': 'right' }, | |
None, | |
{ 'firstName': 'Brandell', 'lastName': 'Frobb', 'age': 10, 'handed': 'left' }, | |
]) | |
if __name__ == '__main__': | |
EXERCISE_0() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment