li = [5,6,77,45,22, 2 ,12,35,57]
for i in li:
# print(i)
if (i%2 == 0):
print(i)
li.remove(i)
else:
pass
print(li)
why my output is coming this [5, 77, 45, 12]
after writing above code
li = [5,6,77,45,22, 2 ,12,35,57]
for i in li:
# print(i)
if (i%2 == 0):
print(i)
li.remove(i)
else:
pass
print(li)
why my output is coming this [5, 77, 45, 12]
after writing above code
append the odd numbers to a new list instead
li = [5,6,77,45,22, 2 ,12,35,57]
li2 = []
for i in li:
if (i%2 != 0):
print(i)
li2.append(i)
else:
pass
print(li2)