Two variable dictionary comprehension

Deborah Swanson python at
Mon Apr 3 18:09:44 EDT 2017

Nathan Ernst wrote, on April 03, 2017 1:59 PM
> I was a bit surprised when I looked at the language reference 
> for 3.6.x. I expected there'd be a direct link to 
> comprehensions, but there's not.
> You have to know what you're looking for:
> 6.2.5: List Displays
> 6.2.6: Set Displays
> 6.2.7: Dictionary Displays
> And, then, click on the appropriate element of the sub 
> grammar to find the appropriate syntax.
> So, it took me about 30 seconds to find the appropriate 
> grammars, when I expected it'd only take about 5 seconds, 
> since I'm very familiar with the python docs & how the 
> grammar documentation is laid out.  I can fully understand 
> how someone less familiar with the documentation might have a 
> harder time finding the grammar than I did.
> FWIW, If one was completely new to Python, even knowing the 
> syntax is known as a "comprehension" might be unknown. I 
> certainly didn't know what a comprehension was when I was 
> learning Python. A coworker showed me, some 13 years ago.
> Regards,
> Nate

Thanks Nate, for your comprehension of the plight of many, if not most,
newish Python coders. And it certainly doesn't help to ask the list to
fill in some of the holes and be met with criticism for asking, but I
digress. It is what it is.

Before I started reading the list a few months ago, I'd heard of list
comprehensions in an article I'd read, and hardly understood the gist of
it. But look at me now Ma, I've learned not only how to use list
comprehensions but also a small tribe of other kinds of comprehensions!

(If there's a moral to this story, heck if I know exactly what it is.
"Keep on trying" is as good as any.)


> On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill 
> <malaclypse2 at> wrote:
> > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson 
> > <python at> wrote:
> > > Regular updates as the docs are updated would be a good idea too. 
> > > It's obvious that today's Google isn't up to it, although 
> it occurs 
> > > to me that I haven't tried Google's site search on
> >
> > So, when you search google for the phrase "dict comprehension" or 
> > "dictionary comprehension", nothing useful comes up for 
> you?  When I 
> > search either of those phrases, I get lots of useful 
> results, all of 
> > which spell out how to do what you were originally asking about.  I 
> > know Google search results are skewed by past usage, but 
> I'm surprised 
> > that you didn't find anything useful in the first couple of search 
> > results.
> >
> > When I do a search for 'dict comprehension' I get a boxed result 
> > linking to PEP 274 as the first hit, then two Stack Overflow 
> > questions, both of which demonstrate how to do dictionary 
> > comprehensions.  Following that is another link to PEP 274, 
> a link to 
> > the Python docs on data structures (which does talk about dict 
> > comprehensions, but it's way down on the page), and then links to a 
> > bunch of tutorials.  If you had to judge based on my search 
> results, 
> > Google does a fine job of answering python questions, at least when 
> > you already know the key phrase to look for.
> >
> > --
> > Jerry
> > --
> >
> >
> -- 

More information about the Python-list mailing list