For each of today’s exercises, give the answer to the exercise and draw the memory diagram at the end of the program. Some building blocks will be provided in the Google Slides to help get you started with making memory drawings on the slides.
What does the following program print?
What is the output of each print
call in the following program?
Consider the following program:
a
itself) point to the same list as a
?Implement the following function. Notice that this function returns a new list and leaves in_list
unmodified.
Implement the following function. Notice that this function does not return a new list, but modifies the given list in place. Because the list object being modified is the same one as the caller passed in, we do not need to return another reference to the same object.
def snap(avengers):
""" Remove a randomly chosen half of the
elements from the given list of avengers
"""
# Example usage:
a = [1, 2, 3, 4]
snap(a)
print(a)
# prints [2, 3]
…which brings up an important question: if the world’s population at the time of the snap was odd, did Thanos round up or down?