Ad
  • Default User Avatar

    oh yeah i ha trouble understanding too thanks

  • Default User Avatar

    Hello,

    You're right about set.pop() removing and returning a random element. The missing link here is that when you get to the return statement, the set only ever contains one value because of the problem specifications.

    In the for loop, whether an element ultimately ends in or out of the set is determined by the parity (even or odd) of the number of times it appears: the first time it appears, it's added to the set for the first time, then the next time it's removed from the set, then the next time it's added again, and so on.

    In the end, only elements which appear an odd number of times end up in the set, and according to the problem, there's only one such element in the sequence, so it is the only one that could possibly be returned. So essentially, it is choosing randomly, but it only ever has one option.

    Hope this helps!

  • Default User Avatar

    Hi,

    I was fiddling around with this little bit and I have noticed that "nums.pop()" gives the "nums[0]" value.

    For example, when there was more than one values of "nums", nums.pop() will always spit out the first number in the list.

    I thought set.pop() picks randomly.

    Is there something that I am missing?

    Can someone please explain why its not picking out randomely?

    Thank you.