+ 2

(List and Set) to Tuple anomaly?

** input *** a = [3,8] b = {3,8} print(tuple(a)) print(tuple(b)) *** output *** (3, 8) (8, 3) why???

7th Mar 2017, 2:29 PM
Evgeny Afanasov
Evgeny Afanasov - avatar
4 Réponses
+ 12
in addition to what Mark foxx said sets don't retain the order of the values like dictionaries, their elements are therefore not callable by their index I.e (b[index])
8th Mar 2017, 5:38 PM
Josephine Smith
Josephine Smith - avatar
+ 7
You've printed it as a tuple, and you're not changing the original values neither of a, or b - remaining the same.
7th Mar 2017, 6:38 PM
Mark Foxx
Mark Foxx - avatar
+ 2
thnx to all
8th Mar 2017, 6:10 PM
Evgeny Afanasov
Evgeny Afanasov - avatar
+ 1
But (3,8) != (8,3)
7th Mar 2017, 7:14 PM
Evgeny Afanasov
Evgeny Afanasov - avatar