vendredi 30 mars 2018

if statement to check list items

if I have the following list and variable:

x = [1,2,18,4,5,7,11]
v = 17

and I want (in a single if statement) to search in the list to check if it contains an item that if we subtract it from v variable will equal to one "as example".

For the above example, the If statement will yield True since we have the item 18 (18-17=1) ..

Can we do that in a single if statement with python?!

Aucun commentaire:

Enregistrer un commentaire