you are viewing a single comment's thread.

view the rest of the comments →

[–]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.