I've come across a strange sorting of the Set
while working with the collection. I know that the Set should not be sorted, so I was puzzled by the first example where the thisSetInteger collection is sorted from smallest to largest. In the next example(thisSetIntegers1), after adding more than 4 elements, the collection is not sorted. If I add a String
instead of an Integer
, the values in the collection
are sorted to random. How is this possible?
code:
thisSetIntegers = {4,15,2}
print(thisSetIntegers)
thisSetIntegers1 = {15,4,2,3,100,9,7}
print(thisSetIntegers1)
thisSetString = {"Python", "Java", "C#"}
print(thisSetString)
output
{2, 4, 15}
{2, 3, 100, 4, 7, 9, 15}
{'Python', 'Java', 'C#'}