Maysa A.

asked • 10/19/22

Programming assignment: Memory, Lists, and other collections

Functions 

The signature of each function is provided below, do not make any changes to them, otherwise the tester will not work properly. Make sure there are no input() or print() statements in your code submitted to Gradescope or the autograder will not work properly. 

Backstory: You work for a dating app company; you were hired to write some code to help the app function better. 

def findRecommendations(matches): 

Specific Restrictions (in addition to the general restrictions above): 

  1. You are only allowed .clear(), .append(), len(), range(), .insert(), .extend() 
  2. You may not use sets or dictionaries 

Description: Given a one-dimensional list of dating app matches which contain information in this order [Initials, Gender, Compatibility Score], build a 2D list containing only the matches with a compatibility score of 80 or higher. Include a heart shape for the one match on the list with the highest score. You can append a heart shape to a list by typing .append("\u2665"). 

Parameters: matches is a 1D list of variable size containing match information in this order [Initials (string), Gender (string), Compatibility Score (int)]. 

Return value: None. The list matches is modified in place, and after modification, it is a list of lists. Returning a new list will not work, you must make updates to the matches list. Hint: feel free to make a deep copy of matches, prior to modifying it. 

Assumptions: All input values are valid. The parameter matches will never be empty. There is only one match with the highest score (no duplicate highest scores). 

Examples: 

matches = ["JS", "M", 90, "MS", "M", 76, "JB", "M", 89, "TM", "M", 79] 

findRecommendations(matches) #nothing is returned! 

print(matches) #[['JS', 'M', 90, '♥'], ['JB', 'M', 89]] 

matches = ["JS", "M", 90, "MS", "F", 76, "JB", "M", 89, "TM", "F", 79, "GM", "M", 100, "AB", "F", 65, "SK", "F", 88] 

print(matches) #[] Empty list because no matches with compatibility score 80 or higher 

Explanation: 

Every third item on the given list is the compatibility score, so we loop through each item in the list specifically targeting this value and compare to see if the value is greater than or equal to 80; if it is, we then take that information and make a sublist; which we then append to our main list; creating our list of lists. Once we have our list of lists of matches with high compatibility scores, we search for the one sublist that contains the highest compatibility score, once found, we append the heart shape to that sublist. 

def compressInfo(datingTrack): 

Specific Restrictions (in addition to the general restrictions above): 

  1. You are only allowed .clear(), .append(), len(), range(), .insert(), .extend() 
  2. You may not use sets or dictionaries 

Description: datingTrack is a 2D list (a list of lists) containing a list of dates a member has gone on, the data is stored in this format: [[profile ID, month day year of date gone on]]. 

Format example: [["B111", "10/2/2022"]]. 

Currently datingTrack holds multiple dates gone on with various profile IDs (see examples below). The objective here is to compress the information down so that datingTrack only stores each unique profile ID (string) and the total number of dates gone on (int). The modified information is stored as a list of tuples. 

Parameters: datingTrack is a 2D list (a list of lists) of variable size that contains sub-lists in this format [profile ID (string), month day year of date gone on (string)]. 

Return value: None. The list datingTrack is modified in place, and after modification, it is a list of tuples in this format: [(profile ID (string), total number of dates (int))]. Hint: feel free to make a deep copy of datingTrack, prior to modifying it. 

Assumptions: Assume all input values are valid. Assume a profile ID might appear once or many times in any given datingTrack list. While the profile ID might appear more than once, the same profile ID and date pairing will not appear on the list more than once. 

Examples: 

datingTrack = [["B111", "10/2/2022"], ["B111", "9/25/2022"], ["B222", "8/1/2022"], ["B111", "9/2/2022"]] 

compressInfo(datingTrack) #nothing is returned! 

print(datingTrack) #[('B111', 3), ('B222', 1)] 

Explanation: 

We search through the datingTrack list and keep count of all sublists that contain the same first value (profile ID), once we counted the total, we update our list by appending the profile ID and the count total for that profile ID as a tuple. We will do this until we have gone through all the values in the passed-in list. 

def combineInfo(profileInfo, datingTrack): 

Specific Restrictions (in addition to the general restrictions above): 

  1. You are only allowed .append(), len(), range(), .insert(), .extend() 
  2. You may not use sets or dictionaries 

Description: Given a 2D list (a list of lists) of profileInfo containing each member’s name and their profile ID and given a 2D list (a list of tuples) of datingTrack containing profile ID and total number of dates gone on, append to the profileInfo the total dates gone on. 

Parameters: profileInfo is a 2D list (a list of lists) of variable size that contains member name (string) and profile ID (string). datingTrack is a 2D list (a list of tuples) of variable size containing member profile ID (string) and total dates gone on (int). 

Return value: None. The list profileInfo is modified in place, and after modification, it is a list of lists in this format: [[name (string), profile ID (string), total dates gone on (int)]]. 

Assumptions: Both list inputs will never be empty. All input values are always valid values. The order of profileInfo in each sublist is always name first then ID. The order of datingTrack in each tuple is always ID first then total dates. There could be IDs in the profileInfo list that are not in the datingTrack list and vice versa (see examples below). 

Examples: 

profileInfo = [["Stephanie Jones", "B001"], ["Judith Schmitt", "B002"]] 

datingTrack = [("B002", 3),("B001", 5)] 

Explanation: 

We will loop through both lists given and compare values. We compare the profile ID found in the profileInfo list with the profile ID found in the datingTrack list; once there is a match, we append the second value in the tuple of that matched datingTrack item as the last item of the sublist in profileInfo. If no matches found, profileInfo is not modified. 

def setofNames(profiles, location): 

Specific Restrictions (in addition to the general restrictions above): 

  1. You are only allowed set(), .items(), .values(), .keys(), .add(), .get() 
  2. You should only use sets and dictionaries 

Description: profiles is a dictionary keeping track of the dating app members. The dictionary key is a profile ID, and the value is a list containing: member name, phone number and location. location is a string containing some location search value. This function returns a set containing the member’s names who live in the search value location. 

Parameters: profiles is a dictionary of variable size that contains profile ID (string) as key and the member’s name (string), phone number (string) and location (string) (in list format) as value. location is a string.

 

Return value: a set containing the names of the members (string). 

Note that this function does return something! 

Assumptions: All input values are valid. The order of the list values in the dictionary is: member name first, followed by phone number and then location. 

Examples: 

profiles = { 

"B111" : ["Anahi Saunders", "703-222-2222", "Fairfax"], 

setofNames(profiles, "Fairfax") -> {'Catalina Colon', 'Anahi Saunders', 'Jasiah Fritz'} 

Explanation: 

We first create a new set; as we loop through the dictionary looking for all location matches to the passed-in search value; every time there is a match found, we take the name from that dictionary value and add it to the set. When we have looked through the entire dictionary, we return the populated set. 

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.