Lab 7: Part 2 - More Memory Diagrams

Your task: Writing functions to return specific lists

Create a new file called datingApps.py.

Here is our fictional story for today. There are two new dating apps called fumble and kindling, respectively. Each app uses a list to keep track of their clients. You will write a function for each task below that will return the list shown in the memory diagram.

1. makeFumble0

Partner A
Memory diagram of simple list with string in first location and empty list in second

Write a zero-parameter function called makeFumble0 that returns the list shown above. The diagram shows that there are currently no clients signed up on fumble. Note that the empty box represents an empty list.

You can test your function like this:

fumble0 = makeFumble0()
print(fumble0) # should print ['fumble', []]

2. makeFumble1

Partner B
Memory diagram of simple list with string in first location and a list containing two clients in the second location

Write a zero-parameter function called makeFumble1 that returns the list shown above. The diagram shows that there are now two clients signed up with fumble: 1) 22 year old Rain and 2) 35 year old Jesse.

You can test your function like this:

fumble1 = makeFumble1()
print(fumble1) # should print ['fumble', [['rain', 22], ['jesse', 35]]]

3. makeApps0

Partner A
Memory diagram of a list with two sublits. Each sublist contains the string with the dating app name and a sublist of clients signed up with that app.

Write a zero-parameter function called makeApps0 that returns the list shown above. The diagram shows that there are two different dating apps. Each app has its own client list. Jesse, hoping to maximize their chances, signed up with both apps.

You can test your function like this:

both0 = makeApps0()
print(both0) 
# [['fumble', [['rain', 22], ['jesse', 35]]], ['kindling', [['jesse', 35]]]]

We want to make sure that the two occurrences of Jesse are indeed the same person, so we try this test:

print(both0[0][1][1] is both0[1][1][0]) # Should print True

4. makeApps1

Partner B
Memory diagram of a list with two sublits. Each sublist contains the string with the dating app name and a sublist of clients signed up with that app.

Write a zero-parameter function called makeApps1 that returns the list shown above. The diagram shows that there are two different dating apps. As we saw above, Jesse, hoping to maximize their chances, signed up with both apps. Turns out there is another human named Jesse, also 35, who also signed up with kindling.

You can test your function like this:

both1 = makeApps1()
print(both1) 
# [['fumble', [['rain', 22], ['jesse', 35]]], ['kindling', [['jesse', 35], ['jesse', 35]]]]

You can't see aliasing by just looking at the printed list. We want to make sure that the two Jesses in kindling are not the same person, so we try this test:

print(both1[1][1][0] is both1[1][1][1]) # Should print False

Table of Contents