1
def onlyEvens(L):
    # TODO - your code goes here 
    for i in L:
        if i%2 != 0:
            L.remove(i)
        
    return L

    
if __name__ == '__main__':
    result = onlyEvens ( [ 3,5,6,2,10,8] ) 
    print(result)

when in the funtion the loop only ilterates once i want it so that it'll remove all odd number like 3 and 5 but in the instants it only removes 3 and does get to 5

[6, 2, 10, 8]
  • the reason is while applying `remove` function after removing it actually shifts the indexes of the remaining elements... instead you should create a new list which can store even values.. – Yash Mehta Feb 15 '23 at 04:48

0 Answers0