lst != [] How this expression can be simplified? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

lst != [] How this expression can be simplified?

PyCharm displays the warning.

24th Apr 2019, 3:51 PM
Dmitrii Korottsev
Dmitrii Korottsev - avatar
3 Answers
+ 4
The problem is not in this expression, it should work. But you can just write: if lst: ... Because every list that's not empty is evaluated as True.
24th Apr 2019, 4:47 PM
HonFu
HonFu - avatar
+ 2
HonFu, thanks!
24th Apr 2019, 4:53 PM
Dmitrii Korottsev
Dmitrii Korottsev - avatar
+ 1
It is already a simplified expression. It will be evaluated as true if the list is not empy.
1st Jul 2019, 8:02 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar