def isMixedType(l):
return any( type(l[i]) != type(l[i+1]) for i in range(len(l)-1) )
, , , , , . any
, . any
, .
def mixedTypeSum(l):
numbers_only = ( x for x in l if isinstance(x,(int,float)))
return sum(numbers_only)
isinstance
, , . isinstance(x, (type1,type2 ) )
true, x, 1 2.
sum
.
a = ["cats",4,"n",2,"the",3,"house"]
print(isMixedType(a))
print(mixedTypeSum(a))