Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87512

Re: Dict comprehensions - improvement to docs?

From "Frank Millman" <frank@chagford.com>
Subject Re: Dict comprehensions - improvement to docs?
Date 2015-03-16 08:45 +0200
References <me5pgk$en5$1@ger.gmane.org> <CALwzidnTUifj_L=DSH_8s+z0L44pxVvdpG1+pfz1Tzm=ECTLsw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.415.1426488358.21433.python-list@python.org> (permalink)

Show all headers | View raw


"Ian Kelly" <ian.g.kelly@gmail.com> wrote in message 
news:CALwzidnTUifj_L=DSH_8s+z0L44pxVvdpG1+pfz1Tzm=ECTLsw@mail.gmail.com...
> On Sun, Mar 15, 2015 at 11:25 PM, Frank Millman <frank@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.

Frank


Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 08:45 +0200
  Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-15 23:55 -0700

csiph-web