question 276 Data Models & Typing · medium
SKUs that won't go into a set
SKU codes are typed by hand, so Sku compares them ignoring case and outer spaces: Sku("spo-11681 ") == Sku("SPO-11681"). Deduplicating a list with set(...) now crashes with TypeError: unhashable type: 'Sku'. Make Sku hashable in a way that agrees with its equality, so equal SKUs collapse to one.
Equalitytwo Skus are equal when their codes match after
strip().upper() (keep this)Fixa
__hash__ that agrees with __eq__: equal Skus must have equal hashesThen
unique_skus(skus) (given) returns the distinct codes, sorted