Prepare> Python > Itertools > itertools.permutations()
2023. 8. 5. 22:11ㆍHackerRank-Python
itertools.permutations() | HackerRank
Find all permutations of a given size in a given string.
www.hackerrank.com
문제
Task
You are given a string S.
Your task is to print all possible permutations of size k of the string in lexicographic sorted order.
=> S로 길이가 k인 순열들을 정렬해 출력하라
코드
from itertools import permutations
S, k = input().split()
A = sorted(list(permutations(S, int(k))))
for i in range(len(A)):
print(
''.join(A[i])
)
노트
print(
'\n'.join(sorted(''.join(p) for p in permutations(S,k)))
)
- 압축 형식인가
두 번째 시도
from itertools import permutations
S, k = input().split()
li_s= sorted(list(S))
for i in list(permutations(li_s, int(k))):
print(''.join(i))
참조
HackerRank itertools.permutations() solution in Python
HackerRank itertools.permutations() solution in Python2, python3 and pypy, pypy3 programming language with practical program code example explaination
programs.programmingoneonone.com
'HackerRank-Python' 카테고리의 다른 글
Prepare > Python > Itertools > itertools.combinations_with_replacement() (0) | 2023.08.14 |
---|---|
Prepare > Python > Itertools > itertools.combinations() (0) | 2023.08.13 |
Prepare > Python > Itertools > itertools.product() (0) | 2023.07.29 |
Prepare > Python > Sets > Check Strict Superset (0) | 2023.07.28 |
Prepare > Python > Sets > Check Subset (0) | 2023.07.27 |