0

If all stament not working

Whats wrong with this code it raises syntacs eror if all (if not b.count(i) <2 for i in c) print ("Unique") break

24th Mar 2021, 5:29 PM
Max Lwe
Max Lwe - avatar
8 ответов
+ 1
break should only be used inside loops... anyway, what are b and c? I guess that they are iterables defined before in your code?
24th Mar 2021, 5:34 PM
visph
visph - avatar
0
also you must put colon (:) at end of 'if' line...
24th Mar 2021, 5:35 PM
visph
visph - avatar
0
even after adding the colon still not working the problem is syntax error
24th Mar 2021, 5:40 PM
Max Lwe
Max Lwe - avatar
0
have you also removed the 'break'?
24th Mar 2021, 5:41 PM
visph
visph - avatar
0
Would the break stop it from raising the syntax error It also says the first line is cousing the error.
24th Mar 2021, 5:44 PM
Max Lwe
Max Lwe - avatar
0
oh, excuse me... you don't need the 'if' inside the all parenthesis: if all(not b.count(i) < 2 for i in c): print("Unique") however not sure that your logic is right... you might also wrap condition inside parenthesis: if all(not (b.count(i) < 2) for i in c): print("Unique") to make obvious what to apply 'not'... or simply do: if all(b.count(i) < 2 == False for i in c): print("Unique")
24th Mar 2021, 5:50 PM
visph
visph - avatar
0
You right i didnt check if my logic is write i wanted to know how to use the if all statement . I will fix the logical problems that i have . At the end you have been of a great help so THANK YOU VERY MUCH and have a nice day .
24th Mar 2021, 6:02 PM
Max Lwe
Max Lwe - avatar
0
You can also simplify the condition to if all(b.count(i) >= 2 for i in c):
24th Mar 2021, 7:34 PM
Benjamin Jürgens
Benjamin Jürgens - avatar