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


Groups > comp.lang.python > #87512 > unrolled thread

Re: Dict comprehensions - improvement to docs?

Started by"Frank Millman" <frank@chagford.com>
First post2015-03-16 08:45 +0200
Last post2015-03-15 23:55 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#87512 — Re: Dict comprehensions - improvement to docs?

From"Frank Millman" <frank@chagford.com>
Date2015-03-16 08:45 +0200
SubjectRe: Dict comprehensions - improvement to docs?
Message-ID<mailman.415.1426488358.21433.python-list@python.org>
"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


[toc] | [next] | [standalone]


#87513

FromPaul Rubin <no.email@nospam.invalid>
Date2015-03-15 23:55 -0700
Message-ID<878uexfn30.fsf@jester.gateway.sonic.net>
In reply to#87512
"Frank Millman" <frank@chagford.com> writes:
> 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.

Yeah, the library reference should treat list and dict comprehensions
the same way.  I would have thought neither of them belongs in the
library reference, but if listcomps are there then dictcomps should also
be there.  Probably a case of the manual not being updated when
dictcomps were added.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web