diff options
author | Raymond Hettinger <python@rcn.com> | 2003-11-24 07:14:54 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-11-24 07:14:54 (GMT) |
commit | 7e0282f1b1a8586dfe5b71234541ba6d4d35e5f8 (patch) | |
tree | 5c6a102728685956b291ab1c86d0fb58468c1cc4 | |
parent | 2303b1c19abd79c94da327d630cbac6f4e83a05c (diff) | |
download | cpython-7e0282f1b1a8586dfe5b71234541ba6d4d35e5f8.zip cpython-7e0282f1b1a8586dfe5b71234541ba6d4d35e5f8.tar.gz cpython-7e0282f1b1a8586dfe5b71234541ba6d4d35e5f8.tar.bz2 |
Note the addition of set() and frozenset().
-rw-r--r-- | Doc/whatsnew/whatsnew24.tex | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex index 32158b0..0f5e546 100644 --- a/Doc/whatsnew/whatsnew24.tex +++ b/Doc/whatsnew/whatsnew24.tex @@ -25,6 +25,50 @@ full details, you should refer to the documentation for Python 2.4. If you want to understand the complete implementation and design rationale, refer to the PEP for a particular new feature. +%====================================================================== +\section{PEP 218: Built-In Set Objects} + +Two new built-in types, \function{set(iterable)} and +\function{frozenset(iterable)} provide high speed data types for +membership testing, for eliminating duplicates from sequences, and +for mathematical operations like unions, intersections, differences, +and symmetric differences. + +\begin{verbatim} +>>> a = set('abracadabra') # form a set from a string +>>> 'z' in a # fast membership testing +False +>>> a # unique letters in a +set(['a', 'r', 'b', 'c', 'd']) +>>> ''.join(a) # convert back into a string +'arbcd' +>>> b = set('alacazam') # form a second set +>>> a - b # letters in a but not in b +set(['r', 'd', 'b']) +>>> a | b # letters in either a or b +set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l']) +>>> a & b # letters in both a and b +set(['a', 'c']) +>>> a ^ b # letters in a or b but not both +set(['r', 'd', 'b', 'm', 'z', 'l']) +>>> a.add('z') # add a new element +>>> a.update('wxy') # add multiple new elements +>>> a +set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'x', 'z']) +>>> a.remove('x') # take one element out +>>> a +set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'z']) +\end{verbatim} + +The type \function{frozenset()} is an immutable version of \function{set()}. +Since it is immutable and hashable, it may be used as a dictionary key or +as a member of another set. Accordingly, it does not have methods +like \method{add()} and \method{remove()} which could alter its contents. + +\begin{seealso} +\seepep{218}{Adding a Built-In Set Object Type}{Originally proposed by +Greg Wilson and ultimately implemented by Raymond Hettinger.} +\end{seealso} %====================================================================== \section{PEP 322: Reverse Iteration} |