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'])`?

7th Nov 2018, 8:55 PM
ŠŠ»ŠµŠŗсŠ°Š½Š“р Š›ŠµŠ±ŠµŠ“ŠµŠ²
ŠŠ»ŠµŠŗсŠ°Š½Š“р Š›ŠµŠ±ŠµŠ“ŠµŠ² - avatar
3 Answers
+ 4
Sets have a really strange behaviour if you ask me hope this thread helps you https://www.sololearn.com/Discuss/1556797/?ref=app
7th Nov 2018, 9:02 PM
Mbrustler
Mbrustler - avatar
+ 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.
7th Nov 2018, 9:30 PM
Schindlabua
Schindlabua - avatar
+ 1
Because Sets are unordered you can use them to find a random Number šŸ˜‰ https://code.sololearn.com/cKU78zsBb1Y2/?ref=app
7th Nov 2018, 10:21 PM
Sebastian KeƟler
Sebastian KeƟler - avatar