+ 2

Can anyone explain this to me

Why does this code always print in a different order can anyone explain why I’m watching a tutorial and their code prints it in order Maybe we are using different versions of python https://code.sololearn.com/c3gBeVVCUeAB/?ref=app

17th Aug 2018, 12:12 AM
Alex Petrash
Alex Petrash - avatar
4 Answers
+ 6
Your shopping_list is a set, because you defined it using braces { ... }. Sets are unordered, that's why you never get the same order when you pass over its elements. You should make your shopping_list be a list by defining it with square brackets [ ... ].
17th Aug 2018, 12:24 AM
Eduardo Petry
Eduardo Petry - avatar
+ 1
ty for the fast reply i was actually thinking if it was the braces ty very much
17th Aug 2018, 12:26 AM
Alex Petrash
Alex Petrash - avatar
0
What are your Python version ?
17th Aug 2018, 12:22 AM
Lucas
Lucas - avatar
0
That's an interesting code :)
18th Aug 2018, 8:02 PM
Daria Sokolova
Daria Sokolova - avatar