0
Sets
Hi! I have the code: print set('solo') Output: set(['s','l','o']) How does sets detects the order of elements? Why not: `set(['s','o','l'])`?
3 Antworten
+ 4
Sets have a really strange behaviour if you ask me hope this thread helps you
https://www.sololearn.com/Discuss/1556797/?ref=app
+ 3
A set is an unordered collection of things, by definition. That means:
- the guys who make python can choose any order they want (and the guys in the thread did a good job explaining what's happening)
- you can't rely on any order!
If you need an ordered set, you can use OrderedSet.
+ 1
Because Sets are unordered you can use them to find a random Number 😉
https://code.sololearn.com/cKU78zsBb1Y2/?ref=app