Jan-09-2023, 06:21 PM
(Jan-09-2023, 06:08 PM)woooee Wrote:Actually incorrect. Sets are in hash table order, but hash table order is not fixed, or at least not predictable. I ran this code multiple times:Quote:but when converting the alphabet as a string to a set it always takes up the same order.Correct. Sets are hashed (look it up), so they are in hash table order. And you possibly want difference and not == for the two sets.
a = set("ABC") b = set("abc".upper()) c = set("CBA") print(a, b, c)
Output:{'B', 'C', 'A'} {'B', 'C', 'A'} {'B', 'C', 'A'}
{'A', 'B', 'C'} {'A', 'B', 'C'} {'A', 'B', 'C'}
{'B', 'A', 'C'} {'B', 'A', 'C'} {'C', 'A', 'B'}