첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ list 클래스를 사용해 교집합 리스트를 구하는 방법을 보여준다.

 

▶ 예제 코드 (PY)

def Intersect(sourceList1, sourceList2):
    targetList = []

    for x in sourceList1:
        if x in sourceList2 and x not in targetList:
            targetList.append(x)

    return targetList

list1 = list("MOBILE")
list2 = list("MOTOR" )

list3 = Intersect(list1, list2)

print(list1)
print(list2)
print(list3)

"""
['M', 'O', 'B', 'I', 'L', 'E']
['M', 'O', 'T', 'O', 'R']
['M', 'O']
"""
728x90
그리드형(광고전용)
Posted by icodebroker
,