Created
November 21, 2013 00:12
-
-
Save jamesls/7573657 to your computer and use it in GitHub Desktop.
OrderedDict vs. dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import OrderedDict | |
# This will raise a RuntimeError in python3, but will work | |
# in python2. | |
regular_dict = dict(a='a', b='c') | |
for i, j in regular_dict.items(): | |
regular_dict[i + j] = j | |
# This will create an infinite loop and consume all memory | |
# in python3, but work in python2. | |
d = OrderedDict([('a', 'a'), ('b', 'b')]) | |
for i, j in d.items(): | |
d[i + j] = j |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment