About 292,000 results
Open links in new tab
  1. 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, …

  2. Python Dictionary Comprehension - Stack Overflow

    711 There are dictionary comprehensions in Python 2.7+, but they don't work quite the way you're trying. Like a list comprehension, they create a new dictionary; you can't use them to add keys to an …

  3. How can I use if/else in a dictionary comprehension?

    Feb 25, 2012 · Another example in using if/else in dictionary comprehension I am working on data-entry desktop application for my own office work, and it is common for such data-entry application to get all …

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

    Aug 6, 2010 · Uses dictionary comprehension. If you use a version which lacks them (ie Python 2.6 and earlier), make it dict((key, old_dict[key]) for ...). It's the same, though uglier. Note that this, unlike …

  5. Dictionary Comprehension in Python 3 - Stack Overflow

    I found the following stack overflow post about dict comprehensions in Python2.7 and Python 3+: Create a dictionary with list comprehension in Python stating that I can apply dictionary comprehensi...

  6. python - Iterate over a dictionary by comprehension and get a ...

    Mar 7, 2014 · How to iterate over a dictionary by dictionary comprehension to process it.

  7. Conditional expressions in Python Dictionary comprehensions

    Aug 15, 2013 · Conditional expressions in Python Dictionary comprehensions Asked 12 years, 4 months ago Modified 7 years, 4 months ago Viewed 51k times

  8. Nested dictionary comprehension python - Stack Overflow

    Jul 29, 2013 · I haven't found an example of a nested dictionary comprehension like this; Googling "nested dictionary comprehension python" shows legacy examples, non-nested comprehensions, or …

  9. dictionary - Is a python dict comprehension always "last wins" if there ...

    Sep 24, 2016 · If I create a python dictionary with a dict comprehension, but there are duplicate keys, am I guaranteed that the last item will be the one that ends up in the final dictionary? It's not clear to m...

  10. Add an element in each dictionary of a list (list comprehension)

    Dec 28, 2012 · You are using a list comprehension incorrectly, the call to item.update returns a None value and thus your newly created list will be full of None values instead of your expected dict values. …