On 3/16/2015 2:45 AM, Frank Millman wrote:
"Ian Kelly" <ian.g.ke...@gmail.com> wrote in message
news:CALwzidnTUifj_L=DSH_8s+z0L44pxVvdpG1+pfz1Tzm=ect...@mail.gmail.com...
On Sun, Mar 15, 2015 at 11:25 PM, Frank Millman <fr...@chagford.com>
wrote:
Hi all
I like dict comprehensions, but I don't use them very often, so when I do
I
need to look up the format.
[...]
Dict comprehensions aren't covered in the library reference because
they're a language feature, not a part of the standard library. The
syntax is defined at:
https://docs.python.org/3/reference/expressions.html#dictionary-displays
This is what the library reference says about lists -
"""
Lists may be constructed in several ways:
Using a pair of square brackets to denote the empty list: []
Using square brackets, separating items with commas: [a], [a, b, c]
Using a list comprehension: [x for x in iterable]
Using the type constructor: list() or list(iterable)
"""
This is what it says about dictionaries -
"""
Dictionaries can be created by placing a comma-separated list of key: value
pairs within braces, for example: {'jack': 4098, 'sjoerd': 4127} or {4098:
'jack', 4127: 'sjoerd'}, or by the dict constructor.
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
Return a new dictionary initialized from an optional positional argument and
a possibly empty set of keyword arguments.
"""
If you did not know about dict comprehensions, there is nothing to tell you
that they even exist.
I feel that it should be mentioned.
Given that list comprehensions are mentioned in the library reference, I
agree that set and dict comprehensions should be also. Open an issue on
the tracker pointing to the list entry.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list