[TIL] python list subtraction

a = [1,2,3]
b = [4,5,6]

c = a+b
print(c)

a = [1,2,3,4,5,6]
b = [4,5,6]

c = a-b
princ(c)
TypeError: unsupported operand type(s) for -: 'list' and 'list'


a = [1,2,3,4,5,6]
b = [4,5,6]

c = tuple(a) - tuple(b)
print(c)
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'
"""

a = [1,2,3,4,5,6]
b = [4,5,6]

c = set(a) - set(b)
d = list(c)
print(d)

https://stackoverflow.com/questions/3428536/python-list-subtraction-operation

좋은 웹페이지 즐겨찾기