你和朋友都在集动物贴纸,mine 和 friend 是两人手上的贴纸(可能有重复的)。写 sticker_swap(mine, friend),返回 (能换到的, 能送出的):能换到的是朋友有你没有的,能送出的是你有朋友没有的,两个都按字母顺序排好的列表。
sticker_swap(["cat", "dog", "dog"], ["dog", "fox"])→(['fox'], ['cat'])sticker_swap([], ["owl"])→(['owl'], [])def sticker_swap(mine, friend):
mine_set = set(mine)
friend_set = set(friend)
# 在这里写:朋友有、你没有的,排好放进 can_get
can_get = []
# 在这里写:你有、朋友没有的,排好放进 can_give
can_give = []
return (can_get, can_give)
写好了先点「运行」试试示例,没问题再点「提交」。