CodingTest

python : 배열에서 해당 조건에 맞는 요소들이 몇개있는지를 보기

mrawesome 2020. 11. 24. 07:32
def count_occurence( array, val ):
	return len( [ x for x in array if x == val and type(x) == type(val) ] )

# 코드 분석
# examples
count_occurences([1,2,3,1,2,1], 1) 
# 해당 list에서 1이 몇개있는가