File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -556,6 +556,22 @@ \section{Core Changes}
556556\var {level} is a string such as \code {"alpha"}, \code {"beta"}, or
557557\code {""} for a final release.
558558
559+ Dictionaries have an odd new method, \method {setdefault(\var {key},
560+ \var {default})}, which behaves similarly to the existing
561+ \method {get()} method. However, if the key is missing,
562+ \method {setdefault()} both returns the value of \var {default} as
563+ \method {get()} would do, and also inserts it into the dictionary as
564+ the value for \var {key}. Thus, the following lines of code:
565+
566+ \begin {verbatim }
567+ if dict.has_key( key ): return dict[key]
568+ else:
569+ dict[key] = []
570+ return dict[key]
571+ \end {verbatim }
572+
573+ can be reduced to a single \code {return dict.setdefault(key, [])} statement.
574+
559575% ======================================================================
560576\section {Extending/Embedding Changes }
561577
You can’t perform that action at this time.
0 commit comments