generated from mwc/lab_weather
	friend_functions.py
This commit is contained in:
		@@ -48,39 +48,36 @@
 | 
				
			|||||||
#         if (person["name"]==name): # for a dict within a list lookup
 | 
					#         if (person["name"]==name): # for a dict within a list lookup
 | 
				
			||||||
#             return len(person["favorite_colors"]) # count of list elements in a dict within a list
 | 
					#             return len(person["favorite_colors"]) # count of list elements in a dict within a list
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
#     return None # reached the end of the list without a match
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# def people_who_like_color(people, color):
 | 
				
			||||||
 | 
					#     """Returns a list containing only those people who like the given color.
 | 
				
			||||||
 | 
					#         >>> people_who_like_color(family, "yellow")
 | 
				
			||||||
 | 
					#         [
 | 
				
			||||||
 | 
					#             {
 | 
				
			||||||
 | 
					# 	        "name": "Walker Hurley",
 | 
				
			||||||
 | 
					# 	        "email": "auctor.odio@icloud.ca",
 | 
				
			||||||
 | 
					#                 "favorite_colors": ["red", "yellow", "blue", "orange"],
 | 
				
			||||||
 | 
					#             },
 | 
				
			||||||
 | 
					#             {
 | 
				
			||||||
 | 
					# 	        "name": "Clementine Joseph",
 | 
				
			||||||
 | 
					# 	        "email": "hendrerit@aol.co.uk",
 | 
				
			||||||
 | 
					#                 "favorite_colors": ["yellow", "aqua", "black"],
 | 
				
			||||||
 | 
					#             }
 | 
				
			||||||
 | 
					#         ]
 | 
				
			||||||
 | 
					#         >>> people_who_like_color(family, "indigo")
 | 
				
			||||||
 | 
					#         []
 | 
				
			||||||
 | 
					#     """
 | 
				
			||||||
 | 
					#     fav_name=[] # initialize output list as None
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
def people_who_like_color(people, color):
 | 
					#     for person in people:
 | 
				
			||||||
    """Returns a list containing only those people who like the given color.
 | 
					#         if color in person["favorite_colors"]: # if color in the data file matches input color
 | 
				
			||||||
        >>> people_who_like_color(family, "yellow")
 | 
					#             fav_name.append(person) # append output list
 | 
				
			||||||
        [
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
	        "name": "Walker Hurley",
 | 
					 | 
				
			||||||
	        "email": "auctor.odio@icloud.ca",
 | 
					 | 
				
			||||||
                "favorite_colors": ["red", "yellow", "blue", "orange"],
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
	        "name": "Clementine Joseph",
 | 
					 | 
				
			||||||
	        "email": "hendrerit@aol.co.uk",
 | 
					 | 
				
			||||||
                "favorite_colors": ["yellow", "aqua", "black"],
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
        >>> people_who_like_color(family, "indigo")
 | 
					 | 
				
			||||||
        []
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    fav_name=[] # initialize output list as None
 | 
					 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    for person in people:
 | 
					#     return fav_name # at the end of file, output list 
 | 
				
			||||||
        if color in person["favorite_colors"]: # if color in the data file matches input color
 | 
					 | 
				
			||||||
            fav_name.append(person) # append output list
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # print(fav_name)       
 | 
					 | 
				
			||||||
    return fav_name # at the end of file, output list 
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#def count_people_who_like_color(people, color):
 | 
					def count_people_who_like_color(people, color):
 | 
				
			||||||
    """Returns the number of people who like a given color. 
 | 
					    """Returns the number of people who like a given color. 
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        >>> count_people_who_like_color(family, "red")
 | 
					        >>> count_people_who_like_color(family, "red")
 | 
				
			||||||
@@ -88,7 +85,15 @@ def people_who_like_color(people, color):
 | 
				
			|||||||
        >>> count_people_who_like_color(family, "orange")
 | 
					        >>> count_people_who_like_color(family, "orange")
 | 
				
			||||||
        1
 | 
					        1
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
#    raise NotImplementedError()
 | 
					    fav_name=[] # initialize output list as None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for person in people:
 | 
				
			||||||
 | 
					        if color in person["favorite_colors"]: # if color in the data file matches input color
 | 
				
			||||||
 | 
					            fav_name.append(person) # append output list
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					    return len(fav_name) # count of names of matching color
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#def get_color_dict(people):
 | 
					#def get_color_dict(people):
 | 
				
			||||||
    """Returns a dict showing how many people like each color. 
 | 
					    """Returns a dict showing how many people like each color. 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,8 +12,8 @@ from friend_functions import (
 | 
				
			|||||||
   # count_people, 
 | 
					   # count_people, 
 | 
				
			||||||
   # get_email, 
 | 
					   # get_email, 
 | 
				
			||||||
   # count_favorite_colors, 
 | 
					   # count_favorite_colors, 
 | 
				
			||||||
   people_who_like_color, 
 | 
					   # people_who_like_color, 
 | 
				
			||||||
   # count_people_who_like_color,
 | 
					    count_people_who_like_color,
 | 
				
			||||||
   # get_color_dict,
 | 
					   # get_color_dict,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,21 +39,21 @@ from friend_functions import (
 | 
				
			|||||||
#     def test_returns_none_when_person_missing(self):
 | 
					#     def test_returns_none_when_person_missing(self):
 | 
				
			||||||
#         self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None)
 | 
					#         self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestPeopleWhoLikeColor(TestCase):
 | 
					# class TestPeopleWhoLikeColor(TestCase):
 | 
				
			||||||
    def test_returns_correct_length(self):
 | 
					#     def test_returns_correct_length(self):
 | 
				
			||||||
        self.assertEqual(len(people_who_like_color(family, "blue")), 2)
 | 
					#         self.assertEqual(len(people_who_like_color(family, "blue")), 2)
 | 
				
			||||||
        self.assertEqual(len(people_who_like_color(family, "purple")), 0)
 | 
					#         self.assertEqual(len(people_who_like_color(family, "purple")), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_returns_full_dicts(self):
 | 
					#     def test_returns_full_dicts(self):
 | 
				
			||||||
        result = people_who_like_color(family, "orange")
 | 
					#         result = people_who_like_color(family, "orange")
 | 
				
			||||||
        self.assertEqual(len(result), 1)
 | 
					#         self.assertEqual(len(result), 1)
 | 
				
			||||||
        self.assertEqual(result[0]["email"], "auctor.odio@icloud.ca")
 | 
					#         self.assertEqual(result[0]["email"], "auctor.odio@icloud.ca")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# class TestCountPeopleWhoLikeColor(TestCase):
 | 
					class TestCountPeopleWhoLikeColor(TestCase):
 | 
				
			||||||
#     def test_returns_correct_count(self):
 | 
					    def test_returns_correct_count(self):
 | 
				
			||||||
#         self.assertEqual(count_people_who_like_color(friends, "grey"), 2)
 | 
					        self.assertEqual(count_people_who_like_color(friends, "grey"), 2)
 | 
				
			||||||
#         self.assertEqual(count_people_who_like_color(friends, "beige"), 1)
 | 
					        self.assertEqual(count_people_who_like_color(friends, "beige"), 1)
 | 
				
			||||||
#         self.assertEqual(count_people_who_like_color(friends, "cornflower"), 0)
 | 
					        self.assertEqual(count_people_who_like_color(friends, "cornflower"), 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# class TestGetColorDict(TestCase):
 | 
					# class TestGetColorDict(TestCase):
 | 
				
			||||||
#     def test_returns_correct_dict(self):
 | 
					#     def test_returns_correct_dict(self):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user