question 323 Decorators & Context Managers · easy
Case-insensitive arguments
SKUs and station IDs are typed by people, in any case and with stray spaces. Write a decorator ignore_case(func) that strips and lower-cases every text positional argument before calling func, leaving other arguments and keyword arguments alone. It is applied to same_sku(a, b) in the starter. The decorated function keeps its name.
Decorator
ignore_case(func); text positional arguments are passed on as arg.strip().lower()Applied to
same_sku(a, b), which compares two SKUs with ==Identityuse
functools.wrapsExamples
callsame_sku('SPO-11681', ' spo-11681')returnsTrue
callsame_sku('HOM-22847', 'hom-22847')returnsTrue
callsame_sku('TOY-54564', 'TOY-54565')returnsFalse