I created a program where I have a list of elements which are string, int and float. I wanted to remove elements from the list which are not float or the strings which have any vowels in them.
mylist = ['hey', 20.0, 'hey', 'hop', 77, 'orange', 11, 'yay', 19, 'hello', 'xyz', 'mop', 11, 30.5, 90, 'hat', 'on']
index = 0
while (index < len(mylist)):
var = mylist[index]
if type(var) is int:
mylist.pop(index)
if type(var) is str:
i = 0
while (i < len(var)):
char = var[i]
if (char == 'a' or char == 'e' or char == 'i' or char == 'u' or char == 'o'):
mylist.pop(index)
i = i + 1
index = index + 1
print(mylist)
Everything's working fine - the float values remain intact and the int values get popped but
- somehow the elements at certain places are not being popped out of the list even when they are int and
- all strings are getting checked fine but the strings with only 'o' somehow bypass the pop statement.