How can I check if the elements of a list are of the same type, without checking individually every element if possible?
For example, I would like to have a function
Using any(), no need to traverse whole list. Just break as soon as object which is not int or long is found:
int
long
>>> not any(not isinstance(y,(int,long)) for y in [1,2,3]) True >>> not any(not isinstance(y,(int,long)) for y in [1,'a',2,3]) False