Looping for as looping parameter while

1

Since the list cont would have the values:

cont = ['t','f','f','t','f']

You could do something like this:

while(for cont in cont == 'f'):
    pass
    
asked by anonymous 26.07.2016 / 14:30

2 answers

1

You can put a condition when iterating:

letras = ['t','f','f','t','f']

for letra in [i for i in letras if i != 'f']:
    print(letra)

Ver Demonstração

Or put the condition out of loop :

letras = ['t','f','f','t','f']

for letra in letras:
    if letra == 'f':
        continue
    print(letra)

Ver demonstração

    
26.07.2016 / 15:36
2

Yes, but try without while :

for letraF in [letra for letra in cont if letra == 'f']:
    print(letraF)
    
26.07.2016 / 15:11