About 115,000 results
Open links in new tab
  1. How can I remove a key from a Python dictionary?

    See Delete an element from a dictionary for more general approaches to the problem of removing a key from a dict (including ones which produce a modified copy).

  2. python - Delete an element from a dictionary - Stack Overflow

    May 1, 2011 · How do I delete an item from a dictionary in Python? Without modifying the original dictionary, how do I obtain another dictionary with the item removed? See also How can I remove a …

  3. Remove key from dictionary in Python returning new dictionary

    EDIT this will drop the key if exist in the dictionary and will return the dictionary without the key,value pair in python there are functions that alter an object in place, and returns a value instead of the altered …

  4. python - Removing multiple keys from a dictionary safely - Stack …

    Jan 25, 2012 · I know how to remove an entry, 'key' from my dictionary d, safely. You do:

  5. How to delete items from a dictionary while iterating over it?

    Mar 22, 2011 · 464 Can I delete items from a dictionary in Python while iterating over it? I want to remove elements that don't meet a certain condition from the dictionary, instead of creating an …

  6. Proper way to remove keys in dictionary with None values in Python

    What is the proper way to remove keys from a dictionary with value == None in Python?

  7. dictionary - Silently removing key from a python dict - Stack Overflow

    I have a python dict and I'd like to silently remove either None and '' keys from my dictionary so I came up with something like this: try: del my_dict[None] except KeyError: pass try: ...

  8. python - Delete a dictionary item if the key exists - Stack Overflow

    Is there any other way to delete an item in a dictionary only if the given key exists, other than: if key in mydict: del mydict[key] The scenario is that I'm given a collection of keys to be r...

  9. python - deleting entries in a dictionary based on a condition - Stack ...

    Aug 13, 2002 · I want to keep the entries with age <= 30 in the same dictionary. I don't want to write them in different dictionary. @JustinCarrey: Is there a particular reason for this? (There are legitimate …

  10. Elegant way to remove fields from nested dictionaries

    I had to remove some fields from a dictionary, the keys for those fields are on a list. So I wrote this function: def delete_keys_from_dict(dict_del, lst_keys): """ Delete the keys present...