Update docs for duplicate-key-in-dict-literal to relate. to python 3

This commit is contained in:
Joe Farebrother
2025-07-15 10:18:29 +01:00
parent 2ed54d52ad
commit df5f76872f
2 changed files with 7 additions and 7 deletions

View File

@@ -1,2 +1,2 @@
dictionary = {1:"a", 2:"b", 2:"c"}
print dictionary[2]
dictionary = {1:"a", 2:"b", 2:"c"} # BAD: `2` key is duplicated.
print(dictionary[2])

View File

@@ -4,8 +4,8 @@
<qhelp>
<overview>
<p>Dictionary literals are constructed in the order given in the source.
This means that if a key is duplicated the second key-value pair will overwrite
the first as a dictionary can only have one value per key.
This means that if a key is duplicated, the second key-value pair will overwrite
the first; as a dictionary can only have one value per key.
</p>
</overview>
@@ -15,14 +15,14 @@ If they are then decide which value is wanted and delete the other one.</p>
</recommendation>
<example>
<p>This example will output "c" because the mapping between 2 and "b" is overwritten by the
mapping from 2 to "c". The programmer may have meant to map 3 to "c" instead.</p>
<p>The following example will output <code>"c"</code>, because the mapping between 2 and <code>"b"</code> is overwritten by the
mapping from 2 to <code>"c"</code>. The programmer may have meant to map 3 to <code>"c"</code> instead.</p>
<sample src="DuplicateKeyInDictionaryLiteral.py" />
</example>
<references>
<li>Python: <a href="http://docs.python.org/2/reference/expressions.html#dictionary-displays">Dictionary literals</a>.</li>
<li>Python: <a href="http://docs.python.org/3/reference/expressions.html#dictionary-displays">Dictionary literals</a>.</li>
</references>
</qhelp>