+ 2
Differentiation
I am trying to iterate through a list and remove the zeros in it, but Python keeps removing False also. I know False == 0 but.... Is there a way I can tell Python to leave False alone and deal only with 0 https://code.sololearn.com/cH0hAz4U4lA8/?ref=app
6 Antworten
+ 1
0
since False is singleton object,u can use kyword "is" instead to differentiate it..
0
Lily Mea both 'is' and == removes False because False is 0 and False == 0
0
Working code: https://code.sololearn.com/cksa4rBWs01e/?ref=app
The same can be written with the usual "for" loop but annoying with the phone. Using method "remove" bad idea in many cases, because it removes the first element with the specified value, regardless of the program logic.
0
Amazing ideas guys. I eventually found out that the isinstance or type works very well with things like this.