13. remove a Few Things


I'm not stuck here: I just have question.
What are the basic differences between del and remove for dicts?

del dict_name[key_name]


Replace this line with your code.





Hope that helps.


Thanks for your quick reply.

So this means that *.remove(item) *addresses a specific item's name and
removes it, and* del *an index number inside the dictionary. Am I right?


.remove() only works for list, not dictionary's.

for a list, .remove() removes the first instance of the item it can find. So if you would have:

aList = [1,2,3,2]

you get [1,3,2] since remove removes the first two

To delete a key from the dictionary, you can't use remove(), you have too use del



Remove - removes a matching value:

Example -

numbers = [0, 2, 2, 3]
number [0, 2, 3]

Delete - del removes a specific key.

number = [3, 2, 2, 1]
del number[1]

Did you notice that remove( ) is for lists only and del [ ] is for dictionaries.

A dictionary is similar to a list, but you access values by looking up a key instead of an index.
Lists are a datatype you can use to store a collection of different pieces of information as a sequence under a single variable name.

Hope that helps.



Nice you got there first.


Awesome! Thank you a lot. I got it now


Question -

If you wanted to remove all the twos.
Would you type -




nope, you would have to loop over the list, use list comprehension, or slices, it depends on the situation which is best.


Very interesting. Did not think of slicing. Very cool.
Thank you.