Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2337f551
Commit
2337f551
authored
Aug 16, 2000
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mention setdefault() method for dicts
parent
c756bdb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
Doc/whatsnew/whatsnew20.tex
Doc/whatsnew/whatsnew20.tex
+16
-0
No files found.
Doc/whatsnew/whatsnew20.tex
View file @
2337f551
...
...
@@ -556,6 +556,22 @@ added to the \module{sys} module. \code{sys.version_info} is a tuple
\var
{
level
}
is a string such as
\code
{
"alpha"
}
,
\code
{
"beta"
}
, or
\code
{
""
}
for a final release.
Dictionaries have an odd new method,
\method
{
setdefault(
\var
{
key
}
,
\var
{
default
}
)
}
, which behaves similarly to the existing
\method
{
get()
}
method. However, if the key is missing,
\method
{
setdefault()
}
both returns the value of
\var
{
default
}
as
\method
{
get()
}
would do, and also inserts it into the dictionary as
the value for
\var
{
key
}
. Thus, the following lines of code:
\begin{verbatim}
if dict.has
_
key( key ): return dict[key]
else:
dict[key] = []
return dict[key]
\end{verbatim}
can be reduced to a single
\code
{
return dict.setdefault(key, [])
}
statement.
% ======================================================================
\section
{
Extending/Embedding Changes
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment