I want to delete strings("324a" included) and leave only integers in a list. Here is the code;
a = ["345", "sadas", "324a", "14", "john"]
for i in a:
try:
if i == int(i):
continue
except ValueError:
a.remove(i)
print(a)
With this code the output is;
['345', '324a', '14']
Even tho "324a" is not an integer and code should return ValueError the code still does not remove it from the list.
Here is another simple code that shows "324a" is not a integer;
a = "324a"
a = int(a)
print(a)
Output of the code above;
a = int(a)
ValueError: invalid literal for int() with base 10: '324a'
Thanks for the answers in advance!