+ 2

Difference '-' operator giving confusing answer

first = {1, 2, 3, 4, 5, 6} second = {4, 5, 6, 7, 8, 9} print(second - first) #--------------------- #OUTPUT>> {8, 9, 7} #Why not {7, 8, 9} ?

11th Apr 2018, 11:56 AM
Pramod Ugale
Pramod Ugale - avatar
6 Antworten
+ 4
A set is an "unordered" collection of items. That explains a lot.
11th Apr 2018, 12:10 PM
Hallox
Hallox - avatar
+ 1
Hallox is right. Python probably intentionally jumbles the set, to remind people ☺
11th Apr 2018, 12:28 PM
Emma
- 7
I'm no in
11th Apr 2018, 12:30 PM
Kelvin E
- 7
bbm mo
11th Apr 2018, 12:30 PM
Kelvin E
- 7
bbm mo
11th Apr 2018, 12:30 PM
Kelvin E
- 7
bbm mo
11th Apr 2018, 12:30 PM
Kelvin E