.remove(item) vs. del dict_name[key_name]


#1

what is the diffrence between
.remove(item) and del dict_name[key_name] ????


#2

There are three methods for removing items from lists in Python:

foo.remove(value)
Removes the first matching value rather than an index

del foo[index]
Removes a specific index

foo.pop(index)
Removes a specific index and returns the removed element


#3

The .remove(item) will remove the first matching item from your list.The ideas is not specified here.

numbers = [1,1,2,2,3,3,4,4]
numbers.remove(3)
print(numbers)#[1, 1, 2, 2, 3, 4, 4]

The del method will remove an item at the specified index of your data structure

numbers = [1,1,2,2,3,3,4,4]
del numbers[1]# delete whatever is at index 1
print(numbers)#[1, 2, 2, 3, 3, 4, 4]

13. remove a Few Things
#4

@joey42,
http://stackoverflow.com/questions/11520492/difference-between-del-remove-and-pop-on-lists
http://stackoverflow.com/questions/11277432/how-to-remove-a-key-from-a-dictionary
http://stackoverflow.com/questions/11358411/silently-remove-key-from-a-python-dict?lq=1


#5

thanx to all of you. this helped a ton!