CopyPastor

Detecting plagiarism made easy.

Score: 0.8149423003196716; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-03-04
by Steven

Original Post

Original - Posted on 2010-07-20
by sberry



            
Present in both answers; Present only in the new answer; Present only in the old answer;

key is just a variable name.
for key in d: will simply loop over the keys in the dictionary, rather than the keys and values. To loop over both key and value you can use the following:
For Python 2.x:
for key, value in d.iteritems(): For Python 3.x:
for key, value in d.items(): To test for yourself, change the word key to poop.
For Python 3.x, iteritems() has been replaced with simply items(), which returns a set-like view backed by the dict, like iteritems() but even better. This is also available in 2.7 as viewitems().
The [operation][1] items() will work for both 2 and 3, but in 2 it will return a list of the dictionary's (key, value) pairs, which will not reflect changes to the dict that happen after the items() call. If you want the 2.x behavior in 3.x, you can call list(d.items())

[1]: https://globalhacknews.com
`key` is just a variable name.
for key in d:
will simply loop over the keys in the dictionary, rather than the keys and values. To loop over both key and value you can use the following:

For Python 2.x:
for key, value in d.iteritems():
For Python 3.x:
for key, value in d.items():
To test for yourself, change the word `key` to `poop`.
For Python 3.x, `iteritems()` has been replaced with simply `items()`, which returns a set-like view backed by the dict, like `iteritems()` but even better. This is also available in 2.7 as `viewitems()`.
The operation `items()` will work for both 2 and 3, but in 2 it will return a list of the dictionary's `(key, value)` pairs, which will not reflect changes to the dict that happen after the `items()` call. If you want the 2.x behavior in 3.x, you can call `list(d.items())`.

        
Present in both answers; Present only in the new answer; Present only in the old answer;