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
""" | |
This file explores differences in behavior with safely or unsafely iterating on weakref's dictionary types and collections.OrderedDict vs the builtin dictionary type. | |
Tested with CPython 2.7, CPython 3.7 - CPython 3.11. | |
Conclusion: | |
- The dict type can be threadsafe to iterate over keys, values, or items if iterating on a shallow copy (dict.copy()) | |
or by passing the corresponding method to a list or tuple constructor (list(dict.items())). |