카테고리 없음

다른 나머지 리스트에 없는 value만 추출

joannekim0420 2021. 11. 25. 12:53
728x90

extract values that isn't the same value, based on one list

def extract_value_in_list(ref, hyp):
    r = set(ref)
    h = set(hyp)
    #extract value that is in ref but not in hyp
    temp = [x for x in ref if x not in h]
    return temp
    
  ref = ['a','b','c','d']
  hyp = ['b','c','e]
  
new_list = extract_value_in_list(ref, hyp)
print(new_list)

 #output
  ['a','d']

 

ref value 값들을 대상으로 hyp 리스트에 공통 value를 뺀다.