Two variable dictionary comprehension

Jerry Hill malaclypse2 at
Mon Apr 3 23:21:20 EDT 2017

On Mon, Apr 3, 2017 at 5:50 PM, Deborah Swanson
<python at> wrote:
> Ah, but did you actually try to use the proposed solutions on the two
> stackoverflow pages? It's been several weeks now, but I did, and neither
> of those two examples fit my situation, which is why I ended up writing
> my own, and unsatisfactorily at that.

Well, that first Stack Overflow link has the following as the first
part of the highest scored answer:

  In Python 2.6 and earlier, the dict constructor can receive an
iterable of key/value pairs:
  d = dict((key, value) for (key, value) in iterable)

  From Python 2.7 and 3 onwards, you can just use the dict
comprehension syntax directly:
  d = {key: value for (key, value) in iterable}

Isn't that second form the exact thing you were looking for, back in
your first post?

> I'm sorry you think the current edition of Google does such a fine job.
> Has it really been that many years ago that the results Google returned
> from a  properly formatted boolean search were really useful? I'd
> imagine that the old Google would have returned a good 10 pages or more
> (probably a lot more) of urls containing the phrase "dict comprehension"
> or "dictionary comprehension". in which you'd find a rich variety of
> specific situations to glean through. (You wouldn't have needed to
> include "python" in the search phrase, since no other programming
> language that I know of, or other English usage for that matter, has
> dict comprehensions.)

Is this not your experience today?  I just browsed through the first 5
pages of search results for the phrase "dict comprehension" (without
the quotes), and the results seem to be pretty on point.  It's mostly
results talking about python dict comprehensions, general python pages
talking about all sorts of comprehensions (dict, list, and set), and
as you get deeper into the result pages, you start to see some entries
for the word "comprehension" in dictionaries too, which seems like a
reasonable thing to end up mixed in with the desired results.  It goes
on in that vein out to page 11 or so, at which point things seem to
devolve a bit.

I'd be totally sympathetic with your plight if you didn't know the key
phrase 'dict comprehension' to find all of that information.  I'm just
not seeing the poor results you seem to be getting from Google once
you know the term.


More information about the Python-list mailing list