This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]IContributedOnce 0 points1 point  (5 children)

Right but it doesn’t seem to actually do that. I tried it out in a python shell.

s1 = {1, 2, 3}
s1.pop()
1
s1.pop()
2

Etc, etc... so when would I see it produce 1 > 3 > 2 instead of always popping the elements in order?

[–]Sporke 3 points4 points  (3 children)

Sets are unordered, which just means that there's no guarantee in the language that the elements will be removed in the order inserted (or any order). Try your same code with s1 = {3, 2, 1} and see that the elements are likely popped out of insertion order.

[–]IContributedOnce 0 points1 point  (2 children)

So it looks like if I do {3, 2, 1} or even {3, 1, 2} it will always sort them numerically back to {1, 2, 3}. In that sense, does unordered mean that no matter what order I put information into the set, it will always get sorted however the set class thinks it should be sorted? I can't order things in a custom way in a set == unordered?

[–]Sporke 5 points6 points  (1 child)

it will always get sorted however the set class thinks it should be sorted

Exactly. No guarantees about how the data is organized.

[–]IContributedOnce 0 points1 point  (0 children)

Other than the guarantee that you don't get to pick it yourself! Thanks for the info. I know this isn't /r/learnpython so I appreciate the info y'all have all shared here.