About 8,570,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 3 months ago Viewed 116k times

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

    Jun 21, 2009 · dict subclass that calls a factory function to supply missing values This is particularly useful if you are working with dictionaries that always consist of the same data types or structures, …

  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. python - Make a dictionary (dict) from separate lists of keys and ...

    new_dict = dict(zip(keys, values)) In Python 3, zip now returns a lazy iterator, and this is now the most performant approach. dict(zip(keys, values)) does require the one-time global lookup each for dict …

  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. 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 …

  8. How to initialize a dict with keys from a list and empty value in Python?

    How to initialize a dict with keys from a list and empty value in Python? Asked 15 years, 10 months ago Modified 2 years, 10 months ago Viewed 531k times

  9. 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, …

  10. python - How do I sort a dictionary by value? - Stack Overflow

    Mar 5, 2009 · I have a dictionary of values read from two fields in a database: a string field and a numeric field. The string field is unique, so that is the key of the dictionary. I can sort on the keys, but ...