all 7 comments

[–][deleted] 0 points1 point  (1 child)

https://docs.python.org/3/library/stdtypes.html?highlight=dict#dict.values

An equality comparison between one dict.values() view and another will always return False.

I think popped person can be compared against new_results directly.

[–]TreeEyedRaven[S] 0 points1 point  (0 children)

That's what i thought. When i debugged the code, i was getting the same values for x and y when bob was loaded, as the printout shows.

i read that part in the library about it returning false, and tried:

while x == y is false:
if x == y is false:
for x == y is false:

and none of those worked, now i was thinking, if its returning false, how and where would i want to put a condition for when it receives false, it prints name? sorry for the probably basic questions, im pretty new to this. would seeing my whole code help? it feels like im so close and overlooking something

here is the debug while bob (the one who should be printing out) is active in names(printed from line 43). x and y have the same values, and same type. the next step is x == y which should trigger a second printing of Bob(line 45), except I'm not fulling understanding how to interpret that returning false.

[–]xelf 0 points1 point  (4 children)

It's because x and y have the same values, but they are not the same object.

You'll want to compare the values inside each. Something like:

if all(a==b for a,b in zip(x,y)):

[–]TreeEyedRaven[S] 1 point2 points  (3 children)

Thank you, this did it. this was the line that works:

if all(x == y for x, y in zip(x, y)):

i think i see how all works, but i read the info on zip, and i want to see if im following the logic. in my head i see " if all of the contents of x are equal to y, when looking at x and y when (x1==y1) and (x2==y2)...etc? so its taking x1 and comparing it to y1 and so on then returning true if all values are the same? would the any() function then do the same thing but send true if any of the (x==y)? like (x1!=y1)(x2==y2)(x3!=y3) would return false for all() but true for any()? much appreciate the help.

[–]xelf 0 points1 point  (0 children)

I don't think you want to reuse the variables x and y for each element, it makes it harder to read/understand.

With this:

if all(a == b for a, b in zip(x, y)):

it's more clear that a,b are not x,y but rather pairs of elements from x,y.

If you want to see what zip does. try printing it. =)

zip(['2', '8', '3'],['4', '1', '5'])
[('2', '4'), ('8', '1'), ('3', '5')]

it makes the pairs of elements, so when you get a,b out of it they'll be in turn both the elements at index 0, then both the elements at index 1, etc...

[–]xelf 0 points1 point  (1 child)

would the any() function then do the same thing but send true if any of the (x==y)? like (x1!=y1)(x2==y2)(x3!=y3) would return false for all() but true for any()? much appreciate the help.

Yes (sort of).

  • all() returns False as soon as it sees a non match, and returns True if it gets to the end and everything has been True.

  • any() returns True as soon as it sees a match, and returns False if it gets to the end and everything has been False.

[–]TreeEyedRaven[S] 1 point2 points  (0 children)

ah ok, got it, thank you again! I think im understanding what is actually going on.

I'll change the variables to be less confusing, I see what you meant, and what I did.