Skip to content

Instantly share code, notes, and snippets.

@eyaltrabelsi
Last active July 8, 2019 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyaltrabelsi/9b8be03dbcb9c91971b786430469b7b9 to your computer and use it in GitHub Desktop.
Save eyaltrabelsi/9b8be03dbcb9c91971b786430469b7b9 to your computer and use it in GitHub Desktop.
Python trick using ordered dict
>>> 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