| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2ed54d5 commit df5f768
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,2 +1,2 @@ | |||
| 1 | - dictionary = {1:"a", 2:"b", 2:"c"} | ||
| 2 | - print dictionary[2] | ||
| 1 | + dictionary = {1:"a", 2:"b", 2:"c"} # BAD: `2` key is duplicated. | ||
| 2 | + print(dictionary[2]) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,8 +4,8 @@ | |||
| 4 | 4 | <qhelp> | |
| 5 | 5 | <overview> | |
| 6 | 6 | <p>Dictionary literals are constructed in the order given in the source. | |
| 7 | - This means that if a key is duplicated the second key-value pair will overwrite | ||
| 8 | - the first as a dictionary can only have one value per key. | ||
| 7 | + This means that if a key is duplicated, the second key-value pair will overwrite | ||
| 8 | + the first; as a dictionary can only have one value per key. | ||
| 9 | 9 | </p> | |
| 10 | 10 | ||
| 11 | 11 | </overview> | |
@@ -15,14 +15,14 @@ If they are then decide which value is wanted and delete the other one.</p> | |||
| 15 | 15 | ||
| 16 | 16 | </recommendation> | |
| 17 | 17 | <example> | |
| 18 | - <p>This example will output "c" because the mapping between 2 and "b" is overwritten by the | ||
| 19 | - mapping from 2 to "c". The programmer may have meant to map 3 to "c" instead.</p> | ||
| 18 | + <p>The following example will output <code>"c"</code>, because the mapping between 2 and <code>"b"</code> is overwritten by the | ||
| 19 | + mapping from 2 to <code>"c"</code>. The programmer may have meant to map 3 to <code>"c"</code> instead.</p> | ||
| 20 | 20 | <sample src="DuplicateKeyInDictionaryLiteral.py" /> | |
| 21 | 21 | ||
| 22 | 22 | </example> | |
| 23 | 23 | <references> | |
| 24 | 24 | ||
| 25 | - <li>Python: <a href="http://docs.python.org/2/reference/expressions.html#dictionary-displays">Dictionary literals</a>.</li> | ||
| 25 | + <li>Python: <a href="http://docs.python.org/3/reference/expressions.html#dictionary-displays">Dictionary literals</a>.</li> | ||
| 26 | 26 | ||
| 27 | 27 | </references> | |
| 28 | 28 | </qhelp> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments