generated from mwc/lab_weather
	friend_functions.py
This commit is contained in:
		@@ -77,25 +77,25 @@
 | 
			
		||||
        
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
def count_people_who_like_color(people, color):
 | 
			
		||||
    """Returns the number of people who like a given color. 
 | 
			
		||||
# def count_people_who_like_color(people, color):
 | 
			
		||||
#     """Returns the number of people who like a given color. 
 | 
			
		||||
    
 | 
			
		||||
        >>> count_people_who_like_color(family, "red")
 | 
			
		||||
        2
 | 
			
		||||
        >>> count_people_who_like_color(family, "orange")
 | 
			
		||||
        1
 | 
			
		||||
    """
 | 
			
		||||
    fav_name=[] # initialize output list as None
 | 
			
		||||
#         >>> count_people_who_like_color(family, "red")
 | 
			
		||||
#         2
 | 
			
		||||
#         >>> count_people_who_like_color(family, "orange")
 | 
			
		||||
#         1
 | 
			
		||||
#     """
 | 
			
		||||
#     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
 | 
			
		||||
#     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
 | 
			
		||||
#     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. 
 | 
			
		||||
    Any color liked by any of the people will be included, and only colors
 | 
			
		||||
    liked by someone will be included. The order of items in the dict doesn't matter.
 | 
			
		||||
@@ -112,4 +112,26 @@ def count_people_who_like_color(people, color):
 | 
			
		||||
            "orange": 1,
 | 
			
		||||
        }
 | 
			
		||||
    """
 | 
			
		||||
#   raise NotImplementedError()
 | 
			
		||||
    d={}
 | 
			
		||||
    v=1
 | 
			
		||||
    for person in people:
 | 
			
		||||
        for color_list in person["favorite_colors"]:
 | 
			
		||||
            if color_list in d: # if the current color is already in the list,
 | 
			
		||||
                +v # increment by 1.
 | 
			
		||||
                d[color_list]=d[color_list]+v # In the same key, 
 | 
			
		||||
                # replace the existing value with the incremented value.  
 | 
			
		||||
            else: # Otherwise, the current color is not in the list.
 | 
			
		||||
                v=1 # Reset the value, since a new color must have a value of 1.
 | 
			
		||||
                d[color_list]=v # Append a new key with the value of 1.
 | 
			
		||||
    return(d)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
            
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
		Reference in New Issue
	
	Block a user