[Python] 30초 파이썬 - difference

리미·2020년 5월 6일
0

30 Seconds of Python

목록 보기
3/5

두개의 리스트를 비교해서 다른 값 반환

# [difference.py]
def difference(source, target):
    # source item이랑 target과 비교해서 다른 source 값들을 리턴
    return [item for item in source if item not in target]


if __name__ == '__main__':
    print(difference([1, 2, 4, 5, 6], [1, 2, 5, 7, 8]))
>>> python difference.py
[4, 6]
profile
Python이 하고싶은데 자꾸 Flutter 시켜서 빡쳐서 만든 블로그

0개의 댓글