Last active
July 8, 2019 20:35
-
-
Save eyaltrabelsi/9b8be03dbcb9c91971b786430469b7b9 to your computer and use it in GitHub Desktop.
Python trick using ordered 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 | |
>>> d = OrderedDict.fromkeys('abcde') | |
>>> d.move_to_end('b') | |
>>> ''.join(d.keys()) | |
'acdeb' | |
>>> d.move_to_end('b', last=False) | |
>>> ''.join(d.keys()) | |
'bacde' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment