[Python-checkins]
python/dist/src/Doc/whatsnew whatsnew24.tex, 1.12, 1.13
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Mon Nov 24 02:14:57 EST 2003
- Previous message: [Python-checkins] python/dist/src/Lib/idlelib NEWS.txt, 1.26,
1.27 PyShell.py, 1.82, 1.83 config-keys.def, 1.19,
1.20 configHandler.py, 1.31, 1.32 keybindingDialog.py, 1.11, 1.12
- Next message: [Python-checkins] Prescription MEDS. Valium,
Xanax. ANYTHING and EVERYTHING ... h fxq fxbb
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Doc/whatsnew
In directory sc8-pr-cvs1:/tmp/cvs-serv22504
Modified Files:
whatsnew24.tex
Log Message:
Note the addition of set() and frozenset().
Index: whatsnew24.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew24.tex,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** whatsnew24.tex 20 Nov 2003 22:22:19 -0000 1.12
--- whatsnew24.tex 24 Nov 2003 07:14:54 -0000 1.13
***************
*** 26,29 ****
--- 26,73 ----
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}
%======================================================================
- Previous message: [Python-checkins] python/dist/src/Lib/idlelib NEWS.txt, 1.26,
1.27 PyShell.py, 1.82, 1.83 config-keys.def, 1.19,
1.20 configHandler.py, 1.31, 1.32 keybindingDialog.py, 1.11, 1.12
- Next message: [Python-checkins] Prescription MEDS. Valium,
Xanax. ANYTHING and EVERYTHING ... h fxq fxbb
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Python-checkins
mailing list