Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-29981: Update Index for set, dict, and generator 'comprehensions'#995

Closed
louisom wants to merge 7 commits into
python:masterpython/cpython:masterfrom
louisom:doc_29981Copy head branch name to clipboard
Closed

bpo-29981: Update Index for set, dict, and generator 'comprehensions'#995
louisom wants to merge 7 commits into
python:masterpython/cpython:masterfrom
louisom:doc_29981Copy head branch name to clipboard

Conversation

@louisom

@louisom louisom commented Apr 5, 2017

Copy link
Copy Markdown
Contributor

No description provided.

@mention-bot

Copy link
Copy Markdown

@grapherd, thanks for your PR! By analyzing the history of the files in this pull request, we identified @birkenfeld, @vadmium and @benjaminp to be potential reviewers.

@orsenthil orsenthil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good to me.

Comment thread Doc/glossary.rst Outdated

set comprehension
A compact way to process all or part of the elements in a sequence and
return a set with the results. ``results = {'foo' for _ in range(10)}``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad example. The result is just {'foo'}.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See an example in tutorial.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka thanks for mention, change another example for set comprehension.

@serhiy-storchaka

Copy link
Copy Markdown
Member

It may be worth to mention set and dict comprehensions as ways of creating sets and dicts in stdtypes.rst.

@louisom

louisom commented Apr 10, 2017

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka there are already mention set and dict omprehensions in stdtypes.rst, but not like link comprehension using one section.

Comment thread Doc/glossary.rst Outdated
set comprehension
A compact way to process all or part of the elements in a sequence and
return a set with the results. ``results = {c for c in 'abracadabra' if
c not in 'abc'`` generates a set of strings with ``{'r', 'd'}``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing }

@serhiy-storchaka

Copy link
Copy Markdown
Member

I can't find mentions of set and dict comprehensions in stdtypes.rst.

A list comprehension is mentioned as the one of three ways of creating lists (in addition to the constructor and the bracket construction). But for sets and dicts only two ways of creating are mentioned (the constructor and the brace construction).

@louisom

louisom commented Apr 10, 2017

Copy link
Copy Markdown
Contributor Author

I mistake the outcome, it had written in tutorial/datastructure.rst, not stdtypes.rst

Comment thread Doc/library/stdtypes.rst Outdated
Non-empty sets (not frozensets) can be created by placing a comma-separated list
of elements within braces, for example: ``{'jack', 'sjoerd'}``, in addition to the
:class:`set` constructor.
Non-empty sets (not frozensets) canb be created by several ways:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: canb.

Comment thread Doc/library/stdtypes.rst Outdated
Non-empty sets (not frozensets) can be created by placing a comma-separated list
of elements within braces, for example: ``{'jack', 'sjoerd'}``, in addition to the
:class:`set` constructor.
Non-empty sets (not frozensets) canb be created by several ways:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty sets also can be created by using the constructor and set comprehension.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think empty set can't created by set comprehension, {} return a dict, I'll add up the constructor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{x for x in ()}

We can't say that the set created by a set comprehension is non-empty until we have created it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I didn't thought that way to create a set before.

Comment thread Doc/library/stdtypes.rst Outdated
``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: 'jack', 4127: 'sjoerd'}``
* Using :class:`dict` constructor: ``dict()``,
``dict([('foo', 100), ('bar', 200)])``, ``dict(foo=100, bar=200)``
* Using dict comprehension: ``{x: x ** 2 for x in range(10)}``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Using a dict comprehension"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question, so {} is a dict comprehension, or a dict constructor?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{} is a dict display.

@bitdancer bitdancer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I have some suggestions.

Comment thread Doc/glossary.rst Outdated
Called a hash in Perl.

dictionary comprehension
A compact way to process all or part of the pair elements in a sequence

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"process all or part of the pair elements in a sequence" makes no sense to me in this context. Most likely you just want "to process all or part of the items in a sequence" as with the set comprehension.

I think it would be good include a link to the reference documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread Doc/glossary.rst Outdated
set comprehension
A compact way to process all or part of the elements in a sequence and
return a set with the results. ``results = {c for c in 'abracadabra' if
c not in 'abc'}`` generates a set of strings with ``{'r', 'd'}``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean "generates the set of strings {'r', 'd'}.

I think it would be good to include a link to the reference documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread Doc/library/stdtypes.rst Outdated
* Using :class:`set` constructor: ``set()``, ``set('foobar')``,
``set(['a', 'b', 'foo'])``
* Using a set comprehension: ``{x for x in ()}``,
``{c for c in 'abracadabra' if c not in 'abc'}``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that you adding this paragraph in parallel to the way it is done in list and tuple, it would be best to put it at the beginning of the section, the way it is in list and tuple. I would drop the example of creating the empty set via comprehension, it will just confuse the reader. Please also reorder the sentences so that they are in an order parallel to that used in list and tuple (ie: the constructor sentence is last). This is mostly a trivial style nit, but consistency is good :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I move this into class dict, not sure if you are saying this section. But it is now consistent with list and tuple.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty set comprehension

Comment thread Doc/library/stdtypes.rst Outdated
``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: 'jack', 4127: 'sjoerd'}``
* Using :class:`dict` constructor: ``dict()``,
``dict([('foo', 100), ('bar', 200)])``, ``dict(foo=100, bar=200)``
* Using a dict comprehension: ``{}``, ``{x: x ** 2 for x in range(10)}``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I think this would be better at the start of the section, with the constructor sentence last.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@bitdancer bitdancer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this exception of the one typo, this looks good to me.

Comment thread Doc/library/stdtypes.rst Outdated
.. class:: set([iterable])
frozenset([iterable])

Sets can be created by several ways:b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have a stray 'b' there at the end of the sentence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should self-check this one.

@Mariatta Mariatta added docs Documentation in the Doc dir needs backport to 3.6 labels Jun 7, 2017
Comment thread Doc/glossary.rst
Called a hash in Perl.

dictionary comprehension
A compact way to process all or part of the items in a sequence

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A list/set/dict comprehension processes the items in an iterable.
If the entry for listcomp says 'sequence', it should be changed. I also do not like the 'all or part of' phrase. The iteration runs to completion. If one wants to not run the iteration to completion, one must use an explicit for loop. Perhaps the 'or part' refers to 'if' clauses. But that is a form of processing. If the iterable yields volatile items, they are gone.

Comment thread Doc/glossary.rst

set comprehension
A compact way to process all or part of the elements in a sequence and
return a set with the results. ``results = {c for c in 'abracadabra' if

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment thread Doc/library/stdtypes.rst

Sets can be created by several ways:

* Using a comma-separated list of elements within braces: ``{'jack', 'sjoerd'}``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use 'Use' instead of 'Using' here and rest of list

Comment thread Doc/library/stdtypes.rst
.. class:: set([iterable])
frozenset([iterable])

Sets can be created by several ways:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'by several ways' is not idiomatic. Either 'by several means' or 'in several ways'. The latter is used below for dicts.

@terryjreedy

Copy link
Copy Markdown
Member

Have any of the other reviewers downloaded and applied the patch and rebuilt the doc to check the changes, especially the new index entries?

Comment thread Doc/library/stdtypes.rst

* Using a comma-separated list of elements within braces: ``{'jack', 'sjoerd'}``
* Using a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'}``
* Using the type constructor: ``set()``, ``set('foobar')``, ``set(['a', 'b', 'foo'])``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should still advertise the use of set([...]). We replaced all instances of it with set literals in the stdlib. See http://bugs.python.org/issue22823 for details.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO these examples are not for creating set literals. They demonstrate creating sets from iterables using the type constructor. Without these examples the user can though that {x for x in iterable} is the only way.

@brettcannon

Copy link
Copy Markdown
Member

To try and help move older pull requests forward, we are going through and backfilling 'awaiting' labels on pull requests that are lacking the label. Based on the current reviews, the best we can tell in an automated fashion is that a core developer requested changes to be made to this pull request.

If/when the requested changes have been made, please leave a comment that says, I have made the requested changes; please review again. That will trigger a bot to flag this pull request as ready for a follow-up review.

@willingc

Copy link
Copy Markdown
Contributor

Thanks @louisom for submitting a PR and @serhiy-storchaka, @orsenthil, @terryjreedy, @bitdancer, and @berkerpeksag for the reviews.

To try and help move older pull requests forward, I'm closing this PR since it has been languishing for almost a year.

@willingc willingc closed this May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes docs Documentation in the Doc dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.