0
Python: any and all
Please, help me: What's happening in the following code: if any(x == y +z or z == x + y for x in range(5) for y in range(-5, 5) for z in range(-10, 10, 2)): print(True) else: print(False) Its the same this? for x in range(5): for y in range(-5, 5): for z in range(-10, 10, 2): if (x == y + z or z == x + y): check = 1 else: check = 0 if check == 1: print(True) else: print(False) The sequence of the "for var in range(number)" in the Second code is same in the First? Thanks
5 Answers
+ 2
Actually they are not the same.
They would be if there were no else statement in the second one (adding check=0 at the start)
Also, there is a performance issue: the second one checks over all the values, even when it's not necessary (when one set of values already turned out to be true)
+ 2
Yes they both are same.
+ 2
Sorry I didn't looked at the code correctly, Angelo is right.
0
Abhay Thanks. I will follow you đ
0
Angelo Thanks. I did not know that. I wil follow you. đ