I have used the set() function but I am confused.
x = set("car")
print(x)
Why does this code output: "a", "c", "r" and not "car"? Thanks for your answers.
>Solution :
It’s because of the main properties of set in Python.
- They can’t contain duplicates
- They’re unordered
So things like this one just happen.
>>> set("car")
{'a', 'r', 'c'}
I suggest you to read this useful documentation about Python’s set.
If you really want an ordered set, there’s something that can be useful to you.
I would suggest you to check this answers too.