Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87509
| References | <me5pgk$en5$1@ger.gmane.org> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2015-03-16 00:17 -0600 |
| Subject | Re: Dict comprehensions - improvement to docs? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.413.1426486700.21433.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-16 00:17 -0600
csiph-web