후보키 - python(programmers)

참치돌고래·2021년 9월 7일
0

알고리즘

목록 보기
26/36
post-custom-banner

https://programmers.co.kr/learn/courses/30/lessons/42890


from itertools import combinations

def check_duplicate(something):
    old = []
    checklist =  [i for i in something if i not in old and not old.append(i) ]
    return len(something) == len(checklist)

def solution(relation):
    answer = 0
    tmp = [i for i in range(len(relation[0]))]
    print(tmp)
    alters = []
    
    for i in range(1,len(relation)):
        alters.append(list(combinations(tmp,i)))
        
    
    check = []
    for alter in alters:
        for a in alter:
            temp = []
            
            for row in relation:
                temp.append([row[i] for i in a])
            
            if check_duplicate(temp) == True:
                for c in check:
                    if set(c).issubset(set(a)):
                        break
                else:
                    check.append(a)
        
                
            
    print(check)
            
    return len(check)
profile
안녕하세요
post-custom-banner

0개의 댓글