skip to Main Content

so, in my book state that:

dict1 = {'satu': 100, 'dua': 100, 'tiga': 100, 'empat':200}
set1 = set(dict1)
set1
{'tiga', 'dua' 'empat' 'satu'}

and while i try it, the code says:

dict1 = {'satu': 100, 'dua': 100, 'tiga': 100, 'empat':200}
set1 = set(dict1)
set1
{'satu', 'dua' 'empat' 'tiga'}

am i mising something?
My code here[text] Book Code description here

2

Answers


  1. Order of the elements in set can change. So you can not expect elements to appear in the same order as they are in book. Main point to note is that set has unique elements.

    Login or Signup to reply.
  2. In the documentation it clearly says that:

    A set is an unordered collection with no duplicate elements.

    So the order doesn’t count, the only thing that matters, in your case, is that the elements of the set are the same as the ones displayed in the book.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search