#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목2022-1-00 기출 7번 문제2023-12-06 15:44
작성자

정답 처리된 답에서는 겹치는 value가 있을 때 그에 대한 key를 모아놓고 나중에 제거하는 방식을 사용하였습니다. 오답 처리된 답에서는 겹치는 value에 대해 그때마다 딕셔너리에서 제거하였습니다. 어디서 차이가 발생한 것인가요?

#7 오답
    def removeCustomerByName(self, customerName):
        count = 0
        for key, value in self.customerInform.items():
            if customerName == value:
                self.customerInform.pop(key)
                count += 1
        if count != 0:
            return self.customerInform
        else:
            return -1
#7 정답
    def removeCustomerByName(self, customerName):
        count = 0
        keyList = []
        for key, value in self.customerInform.items():
            if customerName == value:
                keyList += [key]
                count += 1
        if count != 0:
            for i in keyList:
                self.customerInform.pop(i)
            return self.customerInform
        else:
            return -1
댓글
이전기출질문이요2023-12-06
다음채점 프로그램 질문 2023-12-06