There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in #get-help.
Agree with a comment or answer? Like () to up-vote the contribution!
just learned about the .remove method. However, if I wanted to remove an item in a list in relation to its index, how do I go about this?
…considering the fact that .remove does not accept any parameter, other than the actual item to be removed.
Thank you! In that case, how would you go about removing all the Mangos in the list? Is the only way to use a “for” loop to look for every mango in the list?
In truth if the list was not referenced elsewhere (and didn’t consume an absurd amount of memory) I’d prefer to create a new list skipping all the values that equal ‘mango’, so-
new_store_order_list = [
element
for element in new_store_order_list
if element != 'mango'
]
The problem with removing multiple values is that the length of the list changes when you remove them, so iterating through that list becomes quite difficult. I think a single pass noting the index of each matching element and then removing them in reverse might be a passable option. Sounds like an interesting task if you wanted to give it a shot .
Just went and completed “Shrinking a List: Remove” and there was no requirement to iterate over the list. We use only the .remove() method to remove “Flatbread” and then later, “Mango”, and attempt to remove “Onions” to see the KeyError that gets raised.
you can use del statement like take a example code:
my_list = ['medicine', 'groceries', 'snacks', 'toys']
# if i want to remove snacks cause im getting fatty so i can:
del my_list[2]
print(my_list)
#in output my snacks will be removed :(
Hi everyone, quick question:
For the exercise provide to remove “Mango”, why did it choose to remove the middle position “Mango” instead of the Mango at the last index? Is there a hidden rule behind it?
How come the remove() doesn’t remove both “Chris” indexes in the example?
Is there a way to remove all indexes of a particular string, boolean, int, or float, at the same time?
Also, I do not know how to copy and paste from the example like I’ve seen others do. I tried to do it here and part of my message was formatted as a header and it didn’t look right. How do we copy and paste the example exercises? Thanks!