-1

library version... python: 3.7.4.final.0 pandas: 1.0.0 numpy : 1.18.1

strings = {'one','two','three','four'} 
stri = ["one",'two','three','four']     
print("strings={} \n stri={}".format(strings, stri))   

#elements in strings changes position!!!   output:    strings={'four', 'two', 'three', 'one'} 
#elements in stri remains in same order!!!   output:  stri=['one', 'two', 'three', 'four']

why elements in strings are changing the order?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

1

Sets are unordered collections. They do not have order, that is why you cannot do something like this:

mySet[0]
Alex
  • 151
  • 8
  • 1
    @Selcuk check my updated answer.. I accidentally referred to it as a dictionary but I meant set – Alex Jul 27 '20 at 02:07