In python, set() is an unordered collection with no duplicate elements. However, I am not able to understand how it generates the output.
set()
For example,
As +Volatility and yourself pointed out, sets are unordered. If you need the elements to be in order, just call sorted on the set:
sorted
>>> y = [1, 1, 6, 6, 6, 6, 6, 8, 8] >>> sorted(set(y)) [1, 6, 8]