if statements, comparing lists, python -


what doing wrong if statement doesn't recognise if element in equal 0? attempting print ever 0 program prints . , ever 1 #. cheers.

a=[0,0,1,0,1,1,0,1,1,0,0,0,0,1] print(a) in range(len(a)):     if a[i]==[0]:         print('.', end='')     else:         print('#', end='') print() 

bash:

[0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1] ############## 

you want

if a[i] == 0: 

instead of

if a[i] == [0]: 

you want compare items integer value 0, not single-element list [0].


Comments

Popular posts from this blog

Glib GIOChannel -

delphi - When I encode/decode SMS PDU (GSM 7 Bit) user data, do I need prepend the UDH first? -

python - Obscure curses error message when creating a sub window -