첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
6.15MB

▶ simpleset.py

from functools import *

def Intersect(*argumentTuple):
    "교집합"

    intersectionList = reduce(__Intersect, argumentTuple)

    return intersectionList

def __Intersect(list1, list2):
    targetList = []

    for x in list1:
        if x in list2:
            targetList.append(x)

    return targetList

def Difference(*argumentTuple):
    "차집합"

    targetList = []

    intersectionList = Intersect(*argumentTuple)

    for x in argumentTuple[0]:
        if not x in intersectionList:
            targetList.append(x)

    return targetList

def Union(*argumentTuple):
    "합집합"

    targetList = []

    for item in argumentTuple:
        for x in item:
            if not x in targetList:
                targetList.append(x)

    return sorted(targetList)

 

300x250

 

▶ main.py

import simpleset

sourceList1 = [1, 3, 7, 10]
sourceList2 = [2, 3, 4, 9 ]

print("소스 리스트 1 : ", sourceList1)
print("소스 리스트 2 : ", sourceList2)

intersectionList = simpleset.Intersect(sourceList1, sourceList2)

print("교집합 : ", intersectionList)

differenceList = simpleset.Difference(sourceList1, sourceList2)

print("차집합(소스 리스트 1 - 소스 리스트 2) : ", differenceList)

unionList = simpleset.Union(sourceList1, sourceList2)

print("합집합 : ", unionList)
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요