While not in list

13,549

Solution 1

Your code as written will work fine, except that list.append() returns None, and modifies the list in place; don't assign it back to L:

L=[]
while "END" not in L :
   L.append(something)

Solution 2

>>> a = [1,2,3]
>>> while 12 not in a:
...  a.append(len(a)+1)
...
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

For example ...

Share:
13,549
Reginald
Author by

Reginald

Updated on June 22, 2022

Comments

  • Reginald
    Reginald almost 2 years

    I'm trying to write a code, and I want to ask you how can I ask a while loop to repeat untill it finds a word, in my case END on the list, for example.

    L=[]
    while "END" (not) in L :
       L=L.append(something)
    

    Ask me if you don't understand what I mean.