Firstly, you can del other things besides local variables
del list_item[4] del dictionary["alpha"]
Both of which should be clearly useful. Secondly, using del
on a local variable makes the intent clearer. Compare:
del foo
to
foo = None
I know in the case of del foo
that the intent is to remove the variable from scope. It’s not clear that foo = None
is doing that. If somebody just assigned foo = None
I might think it was dead code. But I instantly know what somebody who codes del foo
was trying to do.
Related Posts:
- I’m getting Key error in python
- How do I merge dictionaries together in Python?
- Are dictionaries ordered in Python 3.6+?
- Delete an element from a dictionary
- Python – How to fix “ValueError: not enough values to unpack (expected 2, got 1)”
- How can you print a variable name in python? [duplicate]
- Python AttributeError: ‘dict’ object has no attribute ‘append’
- Iterating over dictionaries using ‘for’ loops
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- Check if a given key already exists in a dictionary
- How to overcome TypeError: unhashable type: ‘list’
- How does collections.defaultdict work?
- Python Dictionary Comprehension
- Is a Python dictionary an example of a hash table?
- Converting dictionary to JSON
- How do I merge two dictionaries in a single expression (taking union of dictionaries)?
- Python list of dictionaries search
- How can I sort a dictionary by key?
- Updating a dictionary in python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- unhashable type: ‘dict’ Type Error [duplicate]
- How to copy a dictionary and only edit the copy
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How to solve dictionary changed size during iteration error?
- C++ Loop through Map
- DataFrame constructor not properly called
- How does the @property decorator work in Python?
- TypeError: ‘dict’ object is not callable
- Getting key with maximum value in dictionary?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Getting key with maximum value in dictionary?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- How can I get dictionary key as variable directly in Python (not by searching from value)?
- How can I remove a key from a Python dictionary?
- append multiple values for one key in a dictionary [duplicate]
- Convert a python dict to a string and back
- How to add multiple values per key in python dictionary
- Angular map. What is it?
- Map like structure in C: use int and struct to determine a value
- Determine the type of an object?
- enumerate() for dictionary in python
- Reverse / invert a dictionary mapping
- Creating 2D dictionary in Python
- ‘dict’ object has no attribute ‘has_key’
- How to print a dictionary’s key?
- How to find if a given key exists in a C++ std::map
- Converting Dictionary to List?
- How to pretty print nested dictionaries?
- How to index into a dictionary?
- Dictionary text file
- In Python, when to use a Dictionary, List or Set?
- Add a new item to a dictionary in Python
- How can I add new keys to a dictionary?
- How do I efficiently iterate over each entry in a Java Map?
- How to sort Map values by key in Java?
- How can I get list of values from dict?
- How can I print out C++ map values?
- TypeError: string indices must be integers, not str // working with dict
- What is the difference between the HashMap and Map objects in Java?
- How do I format a string using a dictionary in python-3.x?
- Creating a dictionary from a csv file?
- Map to List error: Series object not callable
- How to return dictionary keys as a list in Python?
- Comparing two dictionaries and checking how many (key, value) pairs are equal
- How to save a dictionary to a file?
- Mapping over values in a python dictionary
- TypeError: ‘dict_keys’ object does not support indexing
- How to convert an XML string to a dictionary?
- How do I print the key-value pairs of a dictionary in python
- How do I print the key-value pairs of a dictionary in python
- Python: How to check if keys exists and retrieve value from Dictionary in descending priority
- Appending values to dictionary in Python
- Python dictionary from an object’s fields
- Writing a dictionary to a csv file with one line for every ‘key: value’
- How to convert a file into a dictionary?
- Append a dictionary to a dictionary
- Python Add to dictionary loop
- AttributeError: ‘str’ object has no attribute ‘items’
- How does str(list) work?
- convert csv file to list of dictionaries
- Declaring a multi dimensional dictionary in python
- how to concatenate two dictionaries to create a new one in Python?
- python-How to solve KeyError: 2?
- How to search through dictionaries?
- Change the name of a key in dictionary
- What is an easy way to implement fprintf in python?
- How can I extract all values from a dictionary in Python?
- How is Python’s List Implemented?
- Why are there no hashtables in the C standard library?
- Create a list with initial capacity in Python
- Accessing dict_keys element by index in Python3
- Iterating over dictionary items(), values(), keys() in Python 3
- Map vs Object in JavaScript
- Flatten nested dictionaries, compressing keys
- python dictionary error AttributeError: ‘list’ object has no attribute ‘keys’
- Convert list of dictionaries to a pandas DataFrame
- How to print both strings in a dictionary in Python
- How to iterate (keys, values) in JavaScript?