Two variable dictionary comprehension
nathan.ernst at gmail.com
Mon Apr 3 18:37:01 EDT 2017
No worries, Deborah.
Python is by most measurements a relatively easy/simple language to learn,
but there are always the dusty corners. If you've not already, I recommend
going through the online Python tutorial in it's entirety (
After that, learn the language syntax that wasn't covered in the tutorial
by reading the Language Reference (
https://docs.python.org/3/reference/index.html). The tutorial should be
fairly easy for a straight beginner to follow. The language reference
assumes a little higher-level understanding of programming language
grammar. The Python Language Reference uses a modified BNF syntax (BNF
being Backus-Naur form. You can read about BNF at
https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form). To be honest, I'm
not sure what modifications Python uses to BNF, maybe someone else can shed
some light (or skin) on it.
After you'd done those, peruse the standard library. I don't recommend deep
reading there at this point, but at least a cursory reading so you're
cognizant of libraries that are built-in that may help do things may you
want to do now, or in the future (i.e. make a web request, parse JSON or
XML, handle datetimes).
Remember: Python comes with batteries included.
On Mon, Apr 3, 2017 at 5:09 PM, Deborah Swanson <python at deborahswanson.net>
> 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 gmail.com> wrote:
> > > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson
> > > <python at deborahswanson.net> 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 python.org.
> > >
> > > 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
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list