728x90
반응형
문제 출처:https://school.programmers.co.kr/learn/courses/30/lessons/133499
문제 풀이:
첫 시도:
from itertools import product
def solution(babbling):
speak = ["aya", "ye", "woo", "ma" ]
count = 0
for j in babbling:
for i in range(1,5):
if j in list(map(''.join, product(speak, repeat = i))):
count += 1
return count
product 중복순열을 사용하려 했지만 ayaaya 같은것들 땜에 안됨
그렇다고 그냥 순열 하면 [1,2],[1,3][1,4] 는 나오지만 [2,1] 이렇게는 안나온다. + 순서는 있는데 중복이 없는경우 땜에 안됨
ex) [13231] 이런식
def solution(babbling):
count = 0
for b in babbling:
if "ayaaya" in b or "yeye" in b or "woowoo" in b or "mama" in b:
continue
if not b.replace("aya", " ").replace("ye", " ").replace("woo", " ").replace("ma", " ").replace(" ", ""):
count += 1
return count
연속된 2개가 나오면 안돼서 그냥 "" 에 넣어서 해줬다
반응형
댓글