for i in list - change a list inside a for loop?

Jeff Epler jepler at unpythonic.net
Mon Mar 3 15:06:39 EST 2003


Or maybe
    newlist = [i for i in x if i != 'C']
or maybe
    for i in range(len(x)-1, -1, -1):
        if x[i] == 'C': del x[i]
or maybe
    while 'C' in x:
        x.remove('C')
or maybe:
    i = 0
    while i < len(x):
        if x[i] == 'C': del x[i]
        else: i=i+1

Jeff





More information about the Python-list mailing list