Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
本kata的目标是实现一个差异函数,该函数从一个列表减去另一个列表并返回结果。
It should remove all values from list a
, which are present in list b
.
它应该从列表a中删除列表b中列出的所有值。
array_diff([1,2],[1]) == [2]
If a value is present in b
, all of its occurrences must be removed from the other:
如果b列表中只有一个值,那a列表中出现这个值的元素都要删除
array_diff([1,2,2,2,3],[2]) == [1,3]
FUNDAMENTALS基本原理
ARRAYS数组
DATA TYPES数据类型
train
def array_diff(a, b):
#your code here
c=[]
for index,val in enumerate(a):
if val in b:
continue
c.append(val)
return c
1.Tips: Kata Trainer
Welcome to the kata trainer! A few tips to get you started:
欢迎来到卡塔教练机!让你开始的几个小窍门:<