python / cpython

The Python programming language
https://www.python.org
Other
63.15k stars 30.24k forks source link

set.intersection help suggests 2 sets, while any number > 0 is supported #99967

Open bwagner opened 1 year ago

bwagner commented 1 year ago

set.intersection help suggests 2 sets, while any number > 0 is supported

pydoc set.intersection states:

set.intersection = intersection(...) Return the intersection of two sets as a new set.

(i.e. all elements that are in both sets.)

while in fact one or more sets can be passed to the function, e.g.

>>> set.intersection({0,1,2,3}, {1,2,3,4}, {2,3,4,5})
{2, 3}
>>> set.intersection({0,1,2,3})
{0, 1, 2, 3}
ramvikrams commented 1 year ago

but the doc here https://docs.python.org/3/library/stdtypes.html?highlight=set#set mentions Return a new set with elements common to the set and all others.

rhettinger commented 1 year ago

Here are some proposed edits. I'll add more shortly:

union_doc:
Return the union of this set with zero or more iterables.

An element is in the union set if and only if it occurs
in this set or in one of the input iterables.

intersection_doc:
Return the intersection of this set with zero or more iterables.

An element is in the intersection set if and only if it occurs
in this set and in all of the input iterables.

difference_doc:
Return the difference (complement) of this set with zero or more iterables.

An element is in the intersection set if and only if it occurs
in this set but not in any of the input iterables.

symmetric_difference_doc:
Return the symmetric difference of this set with one iterable.

An element is in the symmetric difference set if and only if
it occurs in either this set or in the iterable but not in both.

issubset_doc:
True if all elements in this set are present in the iterable.

issuperset_doc:
True if all elements in the iterable are present in this set.

update_doc:
Inplace update to the union of this set with zero or more iterables.

Adds the elements from the input iterables to this set.

intersection_update_doc:
Inplace update to the intersection of this set with zero or more iterables.

Removes elements from this set unless they also are found
in all of the input iterables.

difference_update_doc
Inplace update to the difference of this set with the input iterables.

Each element from the input iterables is discarded from this set.
ramvikrams commented 1 year ago

Here are some proposed edits. I'll add more shortly:

union_doc:
Return the union of this set with zero or more iterables.

An element is in the union set if and only if it occurs
in this set or in one of the input iterables.

intersection_doc:
Return the intersection of this set with zero or more iterables.

An element is in the intersection set if and only if it occurs
in this set and in all of the input iterables.

difference_doc:
Return the difference (complement) of this set with zero or more iterables.

An element is in the intersection set if and only if it occurs
in this set but not in any of the input iterables.

but are you not doing the changes

rhettinger commented 1 year ago

Yes, I'll do the changes but want to work out the edits here first. It is a process.

ramvikrams commented 1 year ago

Yes, I'll do the changes but want to work out the edits here first. It is a process.

oh, thanks i didn't know about it.