all() any() . isinstance(), , type signature components. , :
def check_match(signature, components):
return all(any(isinstance(c, s) for c in components) for s in signature)
:
>>> signature = [str, int]
>>> components = [1, 'hello', []]
>>> check_match(signature, components)
True
>>> signature = [float, list]
>>> components = ['apple', 1.0]
>>> check_match(signature, components)
False
: . :
all(...`any()` call... for s in signature)
signature, s. all() True , ...any() call... True. False.
-, ...any() call...:
any(isinstance(c, s) for c in components)
c components , c s . - , any(..) True. c , any(...) False.