This is a little code for making a list that can have only items from a list of types
1 2 3 4 5 | def homogeneous(mylist, *types):
'''
>>> homogeneous([ 12, 3, 4, 4.33, 3.14, 'ola', 'string', [], None, [1, 3, 3], {}], int, type(None)) => [12, 3, 4, None]
'''
return [item for item in mylist if type(item) in types]
|
isinstance() can take a tuple of types so your recipe is almost the same as
The only difference is that isinstance() allows sub-types.