• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Python] 두 리스트에서 차이나는 값만 가져오기

21 Feb 2018

Reading time ~1 minute

Python에서 두 리스트에서 차이나는 값만 가져오기

다음과 같은 리스트가 있을때,

temp1 = ['One', 'Two', 'Three', 'Four']
temp2 = ['One', 'Two']

temp1 - temp2 와 같은 결과를 원한다면 다음의 방법을 사용한다.

In [5]: list(set(temp1) - set(temp2))
Out[5]: ['Four', 'Three']

또는 다음과 같은 방식으로 처리 할 수 있다.

set.intersection(another_set)

출처

  • Get difference between two lists


PythonTIP Share Tweet +1