Created
December 7, 2017 13:55
-
-
Save phalt/0c24844fa346f041a022fd45b6fe7d53 to your computer and use it in GitHub Desktop.
Python 3.6 ordered set using a 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
''' | |
In python 3.6 dictionaries are ordered: | |
"The order-preserving aspect of this new implementation | |
is considered an implementation detail and should | |
not be relied upon." | |
But let's face it, we're going to use it and it is | |
going to become a consistent feature. | |
This is an example of using a Dict to act like an OrderedSet - ordered, unique values. | |
It's way cooler than the standard old `OrderedDict` type. | |
''' | |
my_dict = {'A unique value': None, 'another unique value': None} | |
list(my_dict.keys()) | |
['A unique value', 'another unique value'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment