In Python, is it possible to copy a set in the same order as the original? For example, rather than:
>>> s = {'r','g','b'}
>>> t = {i for i in s}
>>> t
set(['r', 'b', 'g'])
>>>
Can t
be set to:
{'r','g','b'}
In Python, is it possible to copy a set in the same order as the original? For example, rather than:
>>> s = {'r','g','b'}
>>> t = {i for i in s}
>>> t
set(['r', 'b', 'g'])
>>>
Can t
be set to:
{'r','g','b'}
Try manipulating the OrderedDict
from collections
, see http://docs.python.org/2/library/collections.html#collections.OrderedDict.
>>> from collections import OrderedDict
>>> x = ['a','b','c','b','c']
>>> list(OrderedDict.fromkeys(x))
['a', 'b', 'c']