I have the string 'ABBA'. If I turn it into a set, I get this:
In: set('ABBA')
Out: {'A', 'B'}
However, if I join them as a string, it reverses the order:
In: ''.join(set('ABBA'))
Out: 'BA'
The same happens if I try to turn the string into a list:
In: list(set('ABBA'))
Out: ['B', 'A']
Why is this happening and how do I address it?
EDIT
The reason applying sorted
doesn't work is that if I make a set out of 'CDA', it will return 'ACD', thus losing the order of the original string. My question pertains to preserving the original order of the set itself.