vendredi 2 octobre 2020

How to write if statement to satisfy condition it list of tuples

In the following code If statement should satisfy this: If difference of first values of each pair is equal to 1 take action A else take action B. list is T=[(0,3),(1,6),(3,10)]. Therefore, in the first two pairs 1-0=1 code should take action A and in the second pair since 3-1!=1 should take action B. I am not sure how to write this if statement.

for i in range(1,len(T)):
      if T[i+1][0]-T[i][0]==1:
         "Action A"
      else:
          "Action B"

Aucun commentaire:

Enregistrer un commentaire