samedi 8 octobre 2016

How to make exceptions during the iteration of a for loop in python

Sorry in advance for the certainly simple answer to this but I can't seem to figure out how to nest an if ______ in ____: block into an existing for block.

For example, how would I change this block to iterate through each instance of i, omitting odd numbers.

odds = '1 3 5 7 9'.split()
for i in range(x):
   if i in odds: 
      continue
   print(i)

this code works for if i == y but I cannot get it to work with a specific set of "y"s

Aucun commentaire:

Enregistrer un commentaire