[Python] 프로그래머스 / level 2 / 모음사전 / 재귀함수 / 중복순열 / 리스트 순서대로 인덱스 반환

2024. 4. 6. 08:10Coding Test/Python

 

https://school.programmers.co.kr/learn/courses/30/lessons/84512

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

from itertools import product
def solution(word):
    
    dictionary = []
    
    for i in range(1,6):
        for j in product(['A', 'E', 'I', 'O', 'U'], repeat=i):
            dictionary.append(''.join(list(j)))
    
    dictionary.sort()
    
    return dictionary.index(word)+1

 

 

def solution(word):
    dictionary = []
    moum = 'AEIOU'
    
    def recursive(cnt, w):
        if cnt==5:
            return
        for i in range(len(moum)):
            dictionary.append(w + moum[i])
            recursive(cnt+1, w+moum[i])
            
    recursive(0, "")
    
    return dictionary.index(word)+1