Quiz Question 1 of 2
Consider the following code:
all_restaurants = [
"Taco City",
"Burgertown",
"Tacovilla",
"Hotdog station",
"House of tacos",
]
def tacos_only(restaurants):
taco_joints = restaurants.copy()
for taco_joint in taco_joints.copy():
if "taco" not in taco_joint.lower():
taco_joints.remove(taco_joint)
return taco_joints
dinner_options = tacos_only(all_restaurants)
Why do you think the author used the copy method in the for loop here:
for taco_joint in taco_joints.copy():
Choose the correct answer below:
-
A
Modifying a list while looping through it is discouraged as it will produce unexpected results. This code is looping through a copy and then modifying the original.
-
B
It is unnecessary, copy creates an identical copy of the list.
-
C
It follows the indices through iteration, using only valid elements of immutability reference, but sequential.