question 353 Memory & Python Internals · easy
Move an item between two carts in place
A shop lets customers move an item from their cart to their wish list. The page holds references to both lists, so the function must change those lists in place, not build new ones. And when both arguments are the very same list, there is nothing to move.
Function
move_item(source, target, sku)Effectremove the first
sku from source and append it to target, changing both lists in placeReturns
True if the item was moved; False (and nothing changes) when sku isn't in source or when source and target are the same list objectExamples
callmove_item(['SPO-11681', 'HOM-22847'], ['ELE-24781'], 'HOM-22847')returnsTrue
callmove_item(['SPO-11681'], [], 'BOO-58412')returnsFalse
callmove_item(['A', 'B'], ['C'], 'A')returnsTrue