-
Use
d.pop
if you want to capture the removed item, like initem = d.pop("keyA")
. -
Use
del
if you want to delete an item from a dictionary. -
If you want to delete, suppressing an error if the key isn’t in the dictionary:
if thekey in thedict: del thedict[thekey]
More Related Contents:
- My program works but Codeacademy does not acknowledge
- Split Strings into words with multiple word boundary delimiters
- Why does integer division yield a float instead of another integer?
- In Python, how do I determine if an object is iterable?
- What do ellipsis […] mean in a list?
- Tkinter scrollbar for frame
- PYTHONPATH vs. sys.path
- Why is this python generator returning the same value everytime?
- In Python, how does one catch warnings as if they were exceptions?
- python tracing a segmentation fault
- Subclassing Python dictionary to override __setitem__
- How can I do DNS lookups in Python, including referring to /etc/hosts?
- How to SSH and run commands in EC2 using boto3?
- Python subprocess: how to use pipes thrice? [duplicate]
- How to install PIP on Python 3.6?
- Process very large (>20GB) text file line by line
- Make distutils look for numpy header files in the correct place
- Pandas “Group By” Query on Large Data in HDFStore?
- Printing tuple with string formatting in Python
- Best way to join two large datasets in Pandas
- How to detect two different colors using `cv2.inRange` in Python-OpenCV?
- Convert generator object to list for debugging [duplicate]
- how to get access to error message from abort command when using custom error handler
- How to draw rectangle outside of the plot frame in Matplotlib
- Looking for a fast way to find the polygon a point belongs to using Shapely
- Optimal method to find the max of sublist items within list
- import httplib ImportError: No module named httplib
- Using Python and BeautifulSoup (saved webpage source codes into a local file)
- TensorFlow, “‘module’ object has no attribute ‘placeholder'”
- What does the term “blocking” mean in programming?