候補鍵(Programmers 42890)
🧑💻 候补基
relationresult[["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]]2
🧑💻 解決策
このとき、繰り返しチェックは内蔵関数issubsetを使用します.
🧑💻 コード#コード#
from itertools import combinations
def solution(relation):
row = len(relation)
col = len(relation[0])
key_idx = list(range(col))
candidtate_keys = []
if row == 1 : return col
for i in range(1, col + 1) :
for comb in combinations(key_idx, i) :
hist = []
for re in relation :
current_key = [re[c] for c in comb]
if current_key in hist :
break
else :
hist.append(current_key)
else :
for ck in candidtate_keys :
if set(ck).issubset(set(comb)) :
break
else :
candidtate_keys.append(comb)
return len(candidtate_keys)
🧑💻 総評
Reference
この問題について(候補鍵(Programmers 42890)), 我々は、より多くの情報をここで見つけました https://velog.io/@moonpiderman/후보키-Programmers-42890テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol