About 50 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

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

  4. Conditional expressions in Python Dictionary comprehensions

    Aug 15, 2013 · Conditional expressions in Python Dictionary comprehensions Ask Question Asked 12 years, 6 months ago Modified 7 years, 6 months ago

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

  6. python - Use else in dict comprehension - Stack Overflow

    Sep 5, 2016 · python dictionary list-comprehension edited Sep 5, 2016 at 16:23 Łukasz Rogalski 23.3k 10 63 93

  7. Python Dictionary comprehension with condition - Stack Overflow

    Dec 12, 2022 · Python Dictionary comprehension with condition Asked 3 years, 1 month ago Modified 3 years, 1 month ago Viewed 846 times

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

  9. python - multiple key value pairs in dict comprehension - Stack Overflow

    Jun 2, 2014 · 43 A dictionary comprehension can only ever produce one key-value pair per iteration. The trick then is to produce an extra loop to separate out the pairs:

  10. Python: count occurrences in a list using dict comprehension/generator

    Nov 4, 2014 · 12 I want to write some tests to analyse the efficiency of different operations in python, namely a comparison of dictionary comprehensions and dict generators. To test this out, I thought I …