본문 바로가기
개발/Algorithm

[프로그래머스/84512/level2/고득점kit] 모음사전 - 완전탐색, 중복순열 product

by 킴과다페인(chae eun kim) 2023. 8. 10.

내 풀이

#중복순열
from itertools import product

def solution(word):
    answer = 0

    d = []
    for i in range(5):
        d += list(map(''.join, product("AEIOU", repeat = i + 1)))
    d.sort()
    return d.index(word) + 1

코드길이 더 줄인 풀이 - 리스트 컴프리헨션

#중복순열
from itertools import product

def solution(word):
    answer = 0

    d = sorted([''.join(c) for i in range(5) for c in product("AEIOU", repeat = i + 1)])

    return d.index(word) + 1