About 8,330,000 results
Open links in new tab
  1. How do I merge two dictionaries in a single expression in Python?

    How can I merge two Python dictionaries in a single expression? For dictionaries x and y, their shallowly-merged dictionary z takes values from y, replacing those from x. In Python 3.9.0 or greater …

  2. What does *tuple and **dict mean in Python? - Stack Overflow

    What does *tuple and **dict mean in Python? [duplicate] Asked 11 years, 10 months ago Modified 4 months ago Viewed 116k times

  3. python - How can I add new keys to a dictionary? - Stack Overflow

    If a key has to be added to a dictionary that is nested inside a dictionary, dict.setdefault (or collections.defaultdict) is really useful. For example, let's try to add a new key-value pair to mydict …

  4. python - What's the difference between dict () and {}? - Stack Overflow

    d = dict([['hash', 'bang'], ['slash', 'dot']]) And a whole other multitude of ways with the dict() function. So obviously one of the things dict() provides is flexibility in syntax and initialization. But that's not what …

  5. What does `Dict[str, Any]` mean in Python? - Stack Overflow

    May 6, 2020 · The PEP 484 type Dict [str, Any] would be suitable, but it is too lenient, as arbitrary string keys can be used, and arbitrary values are valid. Could someone explain what does arbitrary string …

  6. python - Filter dict to contain only certain keys? - Stack Overflow

    Aug 6, 2010 · I've got a dict that has a whole bunch of entries. I'm only interested in a select few of them. Is there an easy way to prune all the other ones out?

  7. python - Check if a given key already exists in a dictionary - Stack ...

    I wanted to test if a key exists in a dictionary before updating the value for the key. I wrote the following code: if 'key1' in dict.keys(): print "blah" else: print "boo" I think this is not...

  8. 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).

  9. python - How do I merge a list of dicts into a single dict? - Stack ...

    Answers here will overwrite keys that match between two of the input dicts, because a dict cannot have duplicate keys. If you want to collect multiple values from matching keys, see How to merge dicts, …

  10. python - Create a dictionary with comprehension - Stack Overflow

    Python supports dict comprehensions, which allow you to express the creation of dictionaries at runtime using a similarly concise syntax. A dictionary comprehension takes the form {key: value for (key, …