일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- mysql
- counter
- BFS
- sql
- python
- level4
- 완전탐색
- lambda
- 데이터분석
- CodingTest
- programmers
- join
- 조합
- coding
- 코딩
- 연습문제
- Stack
- 코딩테스트
- 프로그래머스
- Level2
- coding test
- collections
- 파이썬
- import re
- time complexity
- itertools
- Queue
- lv4
- 코테
- 시간복잡도
- Today
- Total
ror_coding
[Programmers] 모음 사전 - 84512 본문
728x90
from itertools import product 를 사용해서 사전 만들기 ! (즉, 모든 조합 전부 list에 저장)
아니 .. 비효율로 빠꾸당할 줄 알았는데.. 이게 되네 심지어 짱 빠름..
Question
사전에 알파벳 모음 'A', 'E', 'I', 'O', 'U'만을 사용하여 만들 수 있는, 길이 5 이하의 모든 단어가 수록되어 있습니다. 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA"이며, 마지막 단어는 "UUUUU"입니다.
단어 하나 word가 매개변수로 주어질 때, 이 단어가 사전에서 몇 번째 단어인지 return 하도록 solution 함수를 완성해주세요.
Point
- 모든 조합을 list로 만들기 위해 product(repeat)을 이용.
Code
from itertools import product
def solution(word):
l1 = []
words = ['A','E','I','O','U']
for i in range(1,6):
for j in list(product(words, repeat=i)):
l1.append(''.join(j))
l1.sort()
return l1.index(word)+1
now me
On my github
728x90
'Algorithm > Python' 카테고리의 다른 글
[Programmers] 방문 길이 - 49994 (0) | 2024.12.07 |
---|---|
[Programmers] [3차] n진수 게임 - 17687 (0) | 2024.12.07 |
[Programmers] 롤케이크 자르기 - 132265 (1) | 2024.12.05 |
[Programmers] 타겟 넘버 - 43165 (0) | 2024.12.05 |
[Programmers] 프로세스 - 42587 (0) | 2024.12.04 |