>>> L1 = ["the","end"]
>>> bigramslist = [ ("the","end"), ("end","of"), ("of","the"), ("the","world") ]
>>> tuple(L1) in bigramslist
True
편집 : jsbueno는 지적 목록을 검색하는 것은 O 그대로 어디
>>> bigramsset = set([ ("the","end"), ("end","of"), ("of","the"), ("the","world") ])
>>> L1 = ["the","end"]
>>> tuple(L1) in bigramsset
True
이 세트를 사용하는 (A O (1) 검색 시간 복잡도가 발생합니다 엔). 세트를 작성하는 보조 노트는 추가 O (n)이기도합니다. 그 목록은 사실이 포함 된 경우 당신은 무엇을 결정할 수 있습니다 -
>>> list = ["the", "end"]
>>> bigramslist = [ ("the", "end"), ("end", "of"), ("of", "the"), ("the", "world") ]
>>> def check(list, biglist):
... return [(list[0], list[1]) == big for big in biglist]
...
>>> check(list, bigramslist)
[True, False, False, False]
>>>
이 비교 값 중 하나를 일치 :이를 찾고 계신다면
중복을 찾으십니까? –
일치 (끝, of) 일치 (중, 끝), 또는 튜플이 일치 순서가 같아야합니까? –
예 튜플이 일치하도록 동일한 순서 여야합니다 – Tom