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


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

Re: Dict comprehensions - improvement to docs?

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2015-03-16 00:17 -0600
Last post2015-03-16 00:17 -0600
Articles 1 — 1 participant

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? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-16 00:17 -0600

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

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-03-16 00:17 -0600
SubjectRe: Dict comprehensions - improvement to docs?
Message-ID<mailman.413.1426486700.21433.python-list@python.org>
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.

This surprises me, because I find the syntax very intuitive, at least
if you regularly use other kinds of comprehensions. If you don't often
use comprehensions at all, then I suppose there could be a memory
curve.

[x] is a list. [x for x in y] is a list comprehension. {x:y} is a
dict. {x:y for x,y in z} is a dict comprehension.

> I always struggle to find the information in the Library Reference. The
> obvious location, Mapping Types, shows various constructors, but not the
> comprehension.
>
> https://docs.python.org/3/library/stdtypes.html#mapping-types-dict
>
> So I turn to Google. It shows a couple of StackOverflow questions, and then
> a link to the Data Structures section of the Tutorial, which explains it
> succinctly.
>
> https://docs.python.org/3/tutorial/datastructures.html#dictionaries
>
> I feel that the Library Reference should be updated to include dict
> comprehensions.

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

And an example usage can be found in the tutorial at the link you posted above.

[toc] | [standalone]


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


csiph-web