Instead of writing many ands how to short your code in pythonic way

Question:

sv= 0.000324
if sv != 0.00002 and 0.00003 and 0.00004 and 0.00005 and 0.0002 and 0.0003 and 0.0004 and 0.0005 and 0.000003 and 0.04 and 0.000000090 and 0.000005 and 0.00003 and 0.000000090 and 0.0000003:
    print (sv)

instead of writing many ands or ors is there is a way to make this code shorter or more pythonic way ?

Asked By: J87

||

Answers:

Put all the values in a list and check not in. Example Below

sv= 0.000324
not_sv_list = [0.00002, 0.00003, 0.00004, 0.00005, 0.0002, 0.0003, 0.0004, 
        0.0005, 0.000003, 0.04, 0.000000090, 0.000005, 0.00003, 0.000000090, 0.0000003 ]
if sv not in not_sv_list:
    print (sv)
Answered By: Subhrajyoti Das
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.