I have a list of strings: ['1','2','3','4','5','6','7','8','9']. I tried to convert the list of strings to integers using "for loop". But to my utter surprise and shock, the list contained alternate strings and integers data types.
I tried out for various sizes of lists, and every time it was that the alternate entries got converted.
listt=['1','2','3','4','5','6','7','8','9']
for x in listt:
if type(x)==str: #So that the integer already converted does not enter into loop
intx=int(x)
listt.append(intx)
listt.remove(x)
else:
continue
print(listt)
EXPECTATION: [1, 2, 3, 4, 5, 6, 7, 8, 9]
REALITY: ['2', '4', '6', '8', 1, 3, 5, 7, 9]