0
다른 유형의 개체가 OrderedSet
입니다. 단순화를 위해 그들에게 Apple
과 Orange
의 혼합이라고 부르 자.OrderedSet의 개체 유형 인스턴스 개수가
집합에서 Oranges
의 수를 계산하려면 다음보다 간단한 해결책이 있습니까?
number_of_oranges = 0
for fruit in basket:
if isinstance(fruit, Orange):
number_of_oranges += 1
나는 또한 defaultdict(int)
사용할 수 있지만이 훨씬 더 좋은 보지 않고 난 단지Orange
년대의 번호가 필요 . True
이후