I have a code to get only integers from a list:
list = [i for i in list if isinstance(i, int)]
However, if the list is [True, 19, 19.5, False], it will return [True, 19, False]. I need it to return only [19], not the True and False. How do I do that?
>Solution :
As mentioned in the comment, True/False values are also the instances of int in Python, so you can add one more condition to check if the value is not an instance of bool:
>>> lst = [True, 19, 19.5, False]
>>> [x for x in lst if isinstance(x, int) and not isinstance(x, bool)]
[19]